Search in sources :

Example 81 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project ORCID-Source by ORCID.

the class TestXmlValidity method testAllOrcidMessages.

@Test
public void testAllOrcidMessages() throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath*:**/*message-latest.xml");
    for (Resource resource : resources) {
        LOG.info("Found resource: {}", resource);
        InputStream is = null;
        try {
            is = resource.getInputStream();
            OrcidMessage message = (OrcidMessage) unmarshaller.unmarshal(is);
            validationManager = getValidationManager(message.getMessageVersion());
            validationManager.validateMessage(message);
        } catch (IOException e) {
            Assert.fail("Unable to read resource: " + resource + "\n" + e);
        } catch (JAXBException e) {
            Assert.fail("ORCID message is not well formed: " + resource + "\n" + e);
        } catch (OrcidValidationException e) {
            Assert.fail("Validation failed: " + resource + "\n" + e.getCause());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}
Also used : InputStream(java.io.InputStream) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) JAXBException(javax.xml.bind.JAXBException) Resource(org.springframework.core.io.Resource) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Test(org.junit.Test)

Example 82 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project PublicCMS-preview by sanluan.

the class ApplicationConfig method mybatisSqlSessionFactoryBean.

/**
 * Mybatis会话工厂
 *
 * @param dataSource
 * @return mybatis session factory
 * @throws IOException
 */
@Bean
public SqlSessionFactoryBean mybatisSqlSessionFactoryBean(DataSource dataSource) throws IOException {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
    configuration.setCacheEnabled(true);
    configuration.setLazyLoadingEnabled(false);
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    bean.setMapperLocations(resolver.getResources("classpath*:mapper/**/*Mapper.xml"));
    bean.setConfiguration(configuration);
    return bean;
}
Also used : Configuration(org.springframework.context.annotation.Configuration) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) FactoryBean(org.springframework.beans.factory.FactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 83 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project CBEC-B2B by A-Cubic.

the class DataSourceConfig method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    // mybatis分页
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "false");
    // props.setProperty("returnPageInfo", "check");
    // props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props);
    // 添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[] { pageHelper });
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 84 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project nextprot-api by calipho-sib.

the class FilePatternDictionary method loadResources.

protected void loadResources() {
    resourcesMap = new TreeMap<>();
    Resource[] resources;
    try {
        resources = new PathMatchingResourcePatternResolver().getResources(getLocation());
        for (Resource r : resources) {
            resourcesMap.put(r.getFilename().replace(getExtension(), ""), Resources.toString(r.getURL(), Charsets.UTF_8));
        }
    } catch (IOException e) {
        throw new NextProtException("Error on loading SQL Dict", e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 85 with PathMatchingResourcePatternResolver

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

the class SchemaLoader method getSchema.

private Resource getSchema(String schemaName) throws IOException {
    if (schemaName.contains("/")) {
        schemaName = schemaName.substring(schemaName.lastIndexOf('/'));
    }
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    String searchPattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/**/" + schemaName;
    Resource[] resources = resourcePatternResolver.getResources(searchPattern);
    if ((resources == null) || (resources.length == 0)) {
        throw new RuntimeException("Could not find schema [" + schemaName + "]");
    }
    return resources[0];
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

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