Search in sources :

Example 56 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project Assignment by WMPeople.

the class AssignmentApplication method sqlSessionFactory.

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    Resource[] res = new PathMatchingResourcePatternResolver().getResources("Mapper/*Mapper.xml");
    sessionFactory.setMapperLocations(res);
    return sessionFactory.getObject();
}
Also used : Resource(org.springframework.core.io.Resource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 57 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.

the class CoreResources method copyImportRulesFiles.

private void copyImportRulesFiles() throws IOException {
    ByteArrayInputStream[] listSrcFiles = new ByteArrayInputStream[3];
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    String[] fileNames = { "rules.xsd", "rules_template.xml", "rules_template_with_notes.xml" };
    Resource[] resources = null;
    FileOutputStream out = null;
    resources = resolver.getResources("classpath*:properties/rules_template*.xml");
    File dest = new File(getField("filePath") + "rules");
    if (!dest.exists()) {
        if (!dest.mkdirs()) {
            throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
        }
    }
    for (Resource r : resources) {
        File f = new File(dest, r.getFilename());
        out = new FileOutputStream(f);
        IOUtils.copy(r.getInputStream(), out);
        out.close();
    }
    Resource[] r1 = resolver.getResources("classpath*:properties/" + fileNames[0]);
    File f1 = new File(dest, r1[0].getFilename());
    out = new FileOutputStream(f1);
    IOUtils.copy(r1[0].getInputStream(), out);
    out.close();
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File)

Example 58 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.

the class CoreResources method copyODMMappingXMLtoResources.

private void copyODMMappingXMLtoResources(ResourceLoader resourceLoader) {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    String[] fileNames = { "cd_odm_mapping.xml" };
    Resource[] resources;
    try {
        resources = resolver.getResources("classpath*:properties/cd_odm_mapping.xml");
    } catch (IOException ioe) {
        OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to read source files");
        oe.initCause(ioe);
        oe.setStackTrace(ioe.getStackTrace());
        logger.debug(ioe.getMessage());
        throw oe;
    }
    File dest = null;
    try {
        dest = new File(getField("filePath"));
        if (!dest.exists()) {
            if (!dest.mkdirs()) {
                throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
            }
        }
        File f = new File(dest, resources[0].getFilename());
        FileOutputStream out = new FileOutputStream(f);
        IOUtils.copy(resources[0].getInputStream(), out);
        out.close();
    } catch (IOException ioe) {
        OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to get web app base path");
        oe.initCause(ioe);
        oe.setStackTrace(ioe.getStackTrace());
        throw oe;
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File)

Example 59 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.

the class CoreResources method copyConfig.

private void copyConfig() throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    Resource[] resources = null;
    FileOutputStream out = null;
    Resource resource1 = null;
    Resource resource2 = null;
    resource1 = resolver.getResource("classpath:datainfo.properties");
    resource2 = resolver.getResource("classpath:extract.properties");
    String filePath = "$catalina.home/$WEBAPP.lower.config";
    filePath = replaceWebapp(filePath);
    filePath = replaceCatHome(filePath);
    File dest = new File(filePath);
    if (!dest.exists()) {
        if (!dest.mkdirs()) {
            throw new OpenClinicaSystemException("Copying files, Could not create directory: " + dest.getAbsolutePath() + ".");
        }
    }
    File f1 = new File(dest, resource1.getFilename());
    File f2 = new File(dest, resource2.getFilename());
    if (!f1.exists()) {
        out = new FileOutputStream(f1);
        IOUtils.copy(resource1.getInputStream(), out);
        out.close();
    }
    if (!f2.exists()) {
        out = new FileOutputStream(f2);
        IOUtils.copy(resource2.getInputStream(), out);
        out.close();
    }
/*
         * 
         * for (Resource r: resources) { File f = new File(dest, r.getFilename()); if(!f.exists()){ out = new
         * FileOutputStream(f); IOUtils.copy(r.getInputStream(), out); out.close(); } }
         */
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File)

Example 60 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project mybatis.flying by limeng32.

the class SqlSessionFactory3Config method sqlSessionFactoryBean.

@Bean(name = "sqlSessionFactoryExamine")
public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    // 配置数据源,此处配置为关键配置,如果没有将 dynamicDataSource作为数据源则不能实现切换
    sessionFactory.setDataSource(dataSourceExamine);
    VFS.addImplClass(SpringBootVFS.class);
    // 扫描Model
    sessionFactory.setTypeAliasesPackage("indi.mybatis.flying");
    sessionFactory.setConfigLocation(new ClassPathResource("Configuration.xml"));
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] ra2 = resolver.getResources("classpath*:indi/mybatis/flying/mapper*/*.xml");
    Resource[] ra = (Resource[]) ArrayUtils.addAll(null, ra2);
    // 扫描映射文件
    sessionFactory.setMapperLocations(ra);
    return sessionFactory;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6