Search in sources :

Example 21 with ResourcePatternResolver

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());
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) IOException(java.io.IOException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException)

Example 22 with ResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) StaticResourceLoader(org.grails.core.io.StaticResourceLoader) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 23 with ResourcePatternResolver

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

Example 24 with ResourcePatternResolver

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

Example 25 with ResourcePatternResolver

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

ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)65 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)62 Resource (org.springframework.core.io.Resource)49 IOException (java.io.IOException)15 Bean (org.springframework.context.annotation.Bean)11 ArrayList (java.util.ArrayList)10 PageHelper (com.github.pagehelper.PageHelper)9 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)9 File (java.io.File)8 Properties (java.util.Properties)8 InputStream (java.io.InputStream)5 URL (java.net.URL)5 FileOutputStream (java.io.FileOutputStream)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2