Search in sources :

Example 76 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-boot by spring-projects.

the class SpringPackageScanClassResolver method scan.

private Resource[] scan(ClassLoader loader, String packageName) throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
    String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class";
    Resource[] resources = resolver.getResources(pattern);
    return resources;
}
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)

Example 77 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class ConfigApiHelper method registerResources.

/**
 * Register configuration files in IManager implementationss, based on the source of the method call
 * @param file  The configuration file to be registered or unregistered
 * @return  Success or failure of the operation
 */
public static boolean registerResources(File file, FileContentsHelper fileContents) {
    boolean isSuccess = true;
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (IManager manager : ManagerRepositoryService.getInstance().getManagerMap().values()) {
        Resource resource = getMetaInfResource(file, resolver, manager);
        try {
            if (resource.getFile().exists()) {
                if (manager instanceof RoleManager) {
                    PolicyManager.clearCache();
                }
                manager.registerResource(resource, fileContents.getContextSalience(), fileContents.getVariationSalience());
                ManagerRepositoryService.getInstance().add(manager.getClass().getSimpleName(), manager);
                log.debug(resource.getFilename() + " was successfully registered to " + manager);
            }
        } catch (Exception e) {
            isSuccess = false;
            log.error("The resource " + resource.getFilename() + " failed to register", e);
        }
    }
    return isSuccess;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) IManager(org.jaffa.loader.IManager) RoleManager(org.jaffa.loader.policy.RoleManager) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 78 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project commons-dao by reportportal.

the class CriteriaMapFactory method findNeededTypes.

/**
 * Find Classes into specified package
 */
private List<Class<?>> findNeededTypes(String basePackage) {
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
    List<Class<?>> candidates = new LinkedList<>();
    try {
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + "/" + "**/*.class";
        Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                if (isCandidate(metadataReader)) {
                    candidates.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
                }
            }
        }
        return candidates;
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to scan base package '" + basePackage + "'", e);
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) LinkedList(java.util.LinkedList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 79 with PathMatchingResourcePatternResolver

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

the class AnalysisController method attachCohortCharacterizationFiles.

@Override
protected void attachCohortCharacterizationFiles(List<MultipartFile> files) throws IOException, URISyntaxException {
    files.add(new MockMultipartFile(RUN_CC_REPORTS_FILE_NAME, RUN_CC_REPORTS_FILE_NAME, null, readResource("r/" + RUN_CC_REPORTS_FILE_NAME)));
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(PortalStarter.class.getClassLoader());
    List<MultipartFile> multipartFiles = Arrays.stream(resolver.getResources("classpath:/" + CC_SQLS_DIR + "/**")).filter(r -> ((ClassPathResource) r).getPath().endsWith(".sql")).map(this::convertToMultipartFile).collect(Collectors.toList());
    files.addAll(multipartFiles);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) PortalStarter(com.odysseusinc.arachne.portal.PortalStarter) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 80 with PathMatchingResourcePatternResolver

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

the class MybatisConfig method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTypeAliasesPackage(MODEL_PACKAGE + "/*");
    // 配置分页插件,详情请查阅官方文档
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    // 分页尺寸为0时查询所有纪录不再执行分页
    properties.setProperty("pageSizeZero", "true");
    // 页码<=0 查询第一页,页码>=总页数查询最后一页
    properties.setProperty("reasonable", "true");
    // 支持通过 Mapper 接口参数来传递分页参数
    properties.setProperty("supportMethodsArguments", "true");
    pageHelper.setProperties(properties);
    // 添加插件
    factory.setPlugins(new Interceptor[] { pageHelper });
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    // /通过Java配置的方式是通过setConfiguration/setConfigLocation,而setConfigurationProperties只是
    // 配置文件中的一个property。所以mybatis的配置,要不通过XML的location方式,要不就是setConfiguration后
    // 加上property的方式Properties
    // mybatisProperties = new Properties();
    // mybatisProperties.setProperty("mapUnderscoreToCamelCase", "true");
    // factory.setConfigurationProperties(mybatisProperties);
    factory.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));
    return factory.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) 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