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;
}
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;
}
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);
}
}
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);
}
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();
}
Aggregations