use of org.springframework.core.io.support.ResourcePatternResolver in project spring-boot by spring-projects.
the class BeanDefinitionLoader method findPackage.
private Package findPackage(CharSequence source) {
Package pkg = getClass().getClassLoader().getDefinedPackage(source.toString());
if (pkg != null) {
return pkg;
}
try {
// Attempt to find a class in this package
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
Resource[] resources = resolver.getResources(ClassUtils.convertClassNameToResourcePath(source.toString()) + "/*.class");
for (Resource resource : resources) {
String className = StringUtils.stripFilenameExtension(resource.getFilename());
load(Class.forName(source.toString() + "." + className));
break;
}
} catch (Exception ex) {
// swallow exception and continue
}
return getClass().getClassLoader().getDefinedPackage(source.toString());
}
use of org.springframework.core.io.support.ResourcePatternResolver in project grails-core by grails.
the class BinaryGrailsPlugin method getProperties.
/**
* Obtains all properties for this binary plugin for the given locale.
*
* Note this method does not cache so clients should in general cache the results of this method.
*
* @param locale The locale
* @return The properties or null if non exist
*/
public Properties getProperties(final Locale locale) {
Resource url = this.baseResourcesResource;
Properties properties = null;
if (url != null) {
StaticResourceLoader resourceLoader = new StaticResourceLoader();
resourceLoader.setBaseResource(url);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
try {
// first load all properties
Resource[] resources = resolver.getResources('*' + PROPERTIES_EXTENSION);
resources = resources.length > 0 ? filterResources(resources, locale) : resources;
if (resources.length > 0) {
properties = new Properties();
// message bundles are locale specific. The more underscores the locale has the more specific the locale
// so we order by the number of underscores present so that the most specific appears
Arrays.sort(resources, (o1, o2) -> {
String f1 = o1.getFilename();
String f2 = o2.getFilename();
int firstUnderscoreCount = StringUtils.countOccurrencesOf(f1, "_");
int secondUnderscoreCount = StringUtils.countOccurrencesOf(f2, "_");
if (firstUnderscoreCount == secondUnderscoreCount) {
return 0;
} else {
return firstUnderscoreCount > secondUnderscoreCount ? 1 : -1;
}
});
loadFromResources(properties, resources);
}
} catch (IOException e) {
return null;
}
}
return properties;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project new-cloud by xie-summer.
the class MybatisConfigurer method sqlSessionFactoryBean.
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
// 分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
/**
*abel533通用mapper
*/
// MapperInterceptor mapperInterceptor = new MapperInterceptor();
// Properties props = new Properties();
// /**--主键自增回写方法,默认值MYSQL,详细说明请看文档 -->*/
// props.setProperty("IDENTITY","MYSQL");
// /**<!--通用Mapper接口,多个通用接口用逗号隔开 -->*/
// props.setProperty("mappers", "com.github.abel533.mapper.IMapper");
// mapperInterceptor.setProperties(props);
// 添加插件
bean.setPlugins(new Interceptor[] { pageHelper });
// bean.setPlugins(new Interceptor[]{mapperInterceptor});
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
bean.setMapperLocations(resolver.getResources("classpath:mapper/**.xml"));
return bean.getObject();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project new-cloud by xie-summer.
the class MybatisConfigurer method sqlSessionFactoryBean.
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
// 分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
/**
*abel533通用mapper
*/
// MapperInterceptor mapperInterceptor = new MapperInterceptor();
// Properties props = new Properties();
// /**--主键自增回写方法,默认值MYSQL,详细说明请看文档 -->*/
// props.setProperty("IDENTITY","MYSQL");
// /**<!--通用Mapper接口,多个通用接口用逗号隔开 -->*/
// props.setProperty("mappers", "com.github.abel533.mapper.IMapper");
// mapperInterceptor.setProperties(props);
// 添加插件
bean.setPlugins(new Interceptor[] { pageHelper });
// bean.setPlugins(new Interceptor[]{mapperInterceptor});
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
return bean.getObject();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project new-cloud by xie-summer.
the class MybatisConfigurer method sqlSessionFactoryBean.
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
// 分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties);
bean.setPlugins(new Interceptor[] { pageHelper });
// 添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
bean.setMapperLocations(resolver.getResources("classpath:mapper/**.xml"));
return bean.getObject();
}
Aggregations