Java 类org.springframework.core.io.support.PathMatchingResourcePatternResolver 实例源码

项目:busi-support    文件:BusinessDatabaseConfig.java   
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(businessDataSource);
    //mybatis分页
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    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(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
项目:users-service    文件:EmailServiceImpl.java   
private String body(String template, String language, Map<String, String> args) {
    final String templateFile = EMAIL_FILE.replace("*", template);

    try {
        return Files.lines(Paths.get(
            new PathMatchingResourcePatternResolver()
                .getResource(templateFile)
                .getURI()
        )).map(line -> text.format(line, language, args))
            .collect(joining("\n"));
    } catch (final IOException ex) {
        throw new IllegalArgumentException(
            "Could not find email template '" + templateFile + "'."
        );
    }
}
项目:users-service    文件:TextServiceImpl.java   
private Map<String, Map<String, String>> parseLanguageFiles() {
    try {
        return Stream.of(
            new PathMatchingResourcePatternResolver()
                .getResources(MESSAGES_FILE)
        ).collect(toMap(
            this::parseLanguageName,
            this::parseLanguageFile
        ));
    } catch (final IOException ex) {
        throw new RuntimeException(
            "Error loading resourced by pattern '" +
            MESSAGES_FILE + "'.", ex
        );
    }
}
项目:train-simulator    文件:MapBuilderHelper.java   
public static List<String> getMaps() {
  List<String> maps = new ArrayList<>();
  ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  try {
    Resource[] resources = resolver.getResources("maps/*.yaml");
    Arrays.stream(resources).map(Resource::getFilename).map(f -> f.replace(".yaml", ""))
        .filter(s -> !s.equals("defaults"))
        .forEach(maps::add);
  } catch (IOException e) {
    e.printStackTrace();
  }
  File[] localYamls = new File(".").listFiles(
      (dir, name) -> name.toLowerCase().endsWith(".yaml")
  );
  Arrays.stream(localYamls).forEach(f -> maps.add(f.getName().replace(".yaml", "")));

  return maps;
}
项目:read-write-sever    文件:MybatisConfig.java   
@Bean
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(roundRobinDataSouceProxy());
    sqlSessionFactoryBean.setTypeAliasesPackage(this.typeAliasesPackage);
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(this.mapperLocations));
    sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
    return sqlSessionFactoryBean.getObject();
}
项目:Purchase-order-process-template    文件:Config.java   
@Bean
public ProcessEngineConfigurationImpl processEngineConfiguration() throws IOException {
    SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
    config.setDataSource(dataSource());
    config.setTransactionManager(transactionManager());
    config.setDatabaseSchemaUpdate("true");
    config.setJobExecutorActivate(true);
    config.setAuthorizationEnabled(true);
    config.setDefaultSerializationFormat("application/json");
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    config.setDeploymentResources(resolver.getResources("classpath:/bpmn/*.bpmn"));
    List<ProcessEnginePlugin> processEnginePlugins = new ArrayList<>();
    SpinProcessEnginePlugin spinProcessEnginePlugin = new SpinProcessEnginePlugin();
    processEnginePlugins.add(spinProcessEnginePlugin);
    processEnginePlugins.add(CamundaReactor.plugin());
    config.setProcessEnginePlugins(processEnginePlugins);
    return config;
}
项目:buenojo    文件:ResourceHelper.java   
public static void validateResource(String resourcePath,Logger log) 
{ 

    ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
    try {
        if (resourceResolver.getResources("classpath*:/GameData" +resourcePath+"*").length==0)
            log.error("INEXISTENT RESOURCE "+"/GameData" +resourcePath+"*");
    } catch (IOException e) {
        // TODO Auto-generated catch block 
        e.printStackTrace();
    }
}
项目:iBase4J-Common    文件:Configs.java   
public Properties getConfig(ConfigurableEnvironment env) throws IOException {
    PropertiesFactoryBean config = new PropertiesFactoryBean();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    List<Resource> resouceList = InstanceUtil.newArrayList();
    try {
        Resource[] resources = resolver.getResources("classpath*:config/*.properties");
        for (Resource resource : resources) {
            resouceList.add(resource);
        }
    } catch (Exception e) {
        logger.error("", e);
    }
    config.setLocations(resouceList.toArray(new Resource[]{}));
    config.afterPropertiesSet();
    return config.getObject();
}
项目:springboot-smart    文件:Application.java   
@Bean  
@ConditionalOnMissingBean  
public SqlSessionFactory sqlSessionFactory() throws Exception {  
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();  
    sqlSessionFactoryBean.setDataSource(roundRobinDataSouceProxy());  
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
    sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);  
    return sqlSessionFactoryBean.getObject();  
}
项目:rekit-game    文件:LevelManager.java   
/**
 * Load all levels.
 *
 * @throws IOException
 *             iff wrong path.
 */
private static void loadAllLevels() throws IOException {
    PathMatchingResourcePatternResolver resolv = new PathMatchingResourcePatternResolver(ModManager.SYSLOADER);
    Resource[] unknown = resolv.getResources("classpath*:/levels/level*.dat");
    Resource[] subdirs = resolv.getResources("classpath*:/levels/*/level*.dat");
    Resource[] res = new Resource[unknown.length + subdirs.length];
    System.arraycopy(unknown, 0, res, 0, unknown.length);
    System.arraycopy(subdirs, 0, res, unknown.length, subdirs.length);

    Stream<Resource> numbered = Arrays.stream(res).filter(r -> r.getFilename().matches("level_\\d+\\.dat"));
    Stream<Resource> notNumbered = Arrays.stream(res).filter(r -> !r.getFilename().matches("level_\\d+\\.dat"));

    numbered.sorted((r1, r2) -> {
        String n1 = r1.getFilename().substring("level_".length()).split("\\.")[0];
        String n2 = r2.getFilename().substring("level_".length()).split("\\.")[0];
        return Integer.compare(Integer.parseInt(n1), Integer.parseInt(n2));
    }).forEach(LevelManager::addArcadeLevel);
    notNumbered.sorted((r1, r2) -> r1.toString().compareToIgnoreCase(r2.toString())).forEach(LevelManager::addArcadeLevel);

    LevelManager.loadInfiniteLevels();
    LevelManager.loadCustomLevels();
}
项目:alfresco-repository    文件:ModuleServiceImplTest.java   
@Before
public void setUp() throws Exception
{
    moduleService = new ModuleServiceImpl();
    Resource simpleMod = new PathMatchingResourcePatternResolver().getResource("classpath:alfresco/module/simplemodule.properties");
    assertNotNull(simpleMod);
    RegistryService reg = mock(RegistryService.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);

    when(reg.getProperty((RegistryKey) anyObject())).thenAnswer(new Answer<Serializable>()
    {
        public Serializable answer(InvocationOnMock invocation) throws Throwable
        {
            RegistryKey key = (RegistryKey) invocation.getArguments()[0];
            return new ModuleVersionNumber("1.1");
        }
    });
    doReturn(Arrays.asList("fee", "alfresco-simple-module", "fo")).when(reg).getChildElements((RegistryKey) anyObject());
    doReturn(new Resource[] {simpleMod}).when(applicationContext).getResources(anyString());
    moduleService.setRegistryService(reg);
    moduleService.setApplicationContext(applicationContext);
}
项目:springBoot-demo    文件:MyBatisAutoConfiguration.java   
@Bean public SqlSessionFactory sqlSessionFactory() 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", "true");
    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:/me/caixin/dao/mapping/**/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
项目:spring-batch-support    文件:AutomaticJobRegistrarConfigurationSupport.java   
protected List<Class<?>> findMyTypes(String basePackage) throws IOException, ClassNotFoundException {
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);

    List<Class<?>> candidates = new ArrayList<>();
    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(forName(metadataReader.getClassMetadata().getClassName()));
            }
        }
    }
    return candidates;
}
项目:mango-spring-boot-starter    文件:MangoDaoAutoCreator.java   
private List<Class<?>> findMangoDaoClasses(String packages) {
    try {
        List<Class<?>> daos = new ArrayList<Class<?>>();
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
        for (String locationPattern : getLocationPattern(packages)) {
            Resource[] rs = resourcePatternResolver.getResources(locationPattern);
            for (Resource r : rs) {
                MetadataReader reader = metadataReaderFactory.getMetadataReader(r);
                AnnotationMetadata annotationMD = reader.getAnnotationMetadata();
                if (annotationMD.hasAnnotation(DB.class.getName())) {
                    ClassMetadata clazzMD = reader.getClassMetadata();
                    daos.add(Class.forName(clazzMD.getClassName()));
                }
            }
        }
        return daos;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
项目:pay-xxpay-master    文件:DruidDataSourceConfig.java   
@Bean
public SqlSessionFactory sqlSessionFactory() 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", "true");
    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:org/xxpay/dal/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
项目:cc-s    文件:MyBatisConfig.java   
@Bean
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("mybatis.config-location")));
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("mybatis.mapper-locations");
    sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
    sqlSessionFactoryBean.setDataSource(dataSource());

    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", env.getProperty("pageHelper.reasonable"));
    properties.setProperty("supportMethodsArguments", env.getProperty("pageHelper.supportMethodsArguments"));
    properties.setProperty("returnPageInfo", env.getProperty("pageHelper.returnPageInfo"));
    properties.setProperty("params", env.getProperty("pageHelper.params"));
    pageHelper.setProperties(properties);
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});

    return sqlSessionFactoryBean;
}
项目:spring-data-snowdrop    文件:CdiUtils.java   
static NamedQueries findNamedQueries(Class<?> repositoryClass) {
    try {
        RepositoryConfigurationExtension config = new SnowdropRepositoryConfigExtension();
        String location = config.getDefaultNamedQueryLocation();

        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(repositoryClass.getClassLoader());
        ResourceArrayPropertyEditor editor = new ResourceArrayPropertyEditor(resolver, null);
        editor.setAsText(location);
        Resource[] resources = (Resource[]) editor.getValue();

        PropertiesFactoryBean pfb = new PropertiesFactoryBean();
        pfb.setSingleton(false);
        pfb.setLocations(resources);
        pfb.setFileEncoding("UTF-8");
        Properties properties = pfb.getObject();

        return new PropertiesBasedNamedQueries(properties);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
项目:SpringBoot-Study    文件:Read2DruidDataSourceConfig.java   
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read2SqlSessionFactory")
public SqlSessionFactory read2SqlSessionFactory(
        @Qualifier("read2DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read2MapperLocations));

    //配置分页插件
    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);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
项目:SpringBoot-Study    文件:Read1DruidDataSourceConfig.java   
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "read1SqlSessionFactory")
public SqlSessionFactory read1SqlSessionFactory(
        @Qualifier("read1DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(read1MapperLocations));

    //配置分页插件
    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);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
项目:SpringBoot-Study    文件:MasterDruidDataSourceConfig.java   
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(
        @Qualifier("masterDataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // 配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(masterMapperLocations));

    //配置分页插件
    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);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
项目:SpringBoot-Study    文件:ClusterDruidDataSourceConfig.java   
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "clusterSqlSessionFactory")
public SqlSessionFactory clusterSqlSessionFactory(
        @Qualifier("clusterDataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    //配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(clusterMapperLocations));

    //配置分页插件
    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);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
项目:SpringBoot-Study    文件:Cluster1DruidDataSourceConfig.java   
/**
 * SqlSessionFactory配置
 *
 * @return
 * @throws Exception
 */
@Bean(name = "cluster1SqlSessionFactory")
public SqlSessionFactory cluster1SqlSessionFactory(
        @Qualifier("cluster1DataSource") DataSource dataSource
) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    //配置mapper文件位置
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(cluster1MapperLocations));

    //配置分页插件
    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);

    //设置插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    return sqlSessionFactoryBean.getObject();
}
项目:lams    文件:AbstractBeanDefinitionReader.java   
/**
 * Create a new AbstractBeanDefinitionReader for the given bean factory.
 * <p>If the passed-in bean factory does not only implement the BeanDefinitionRegistry
 * interface but also the ResourceLoader interface, it will be used as default
 * ResourceLoader as well. This will usually be the case for
 * {@link org.springframework.context.ApplicationContext} implementations.
 * <p>If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a
 * {@link org.springframework.core.io.support.PathMatchingResourcePatternResolver}.
 * <p>If the the passed-in bean factory also implements {@link EnvironmentCapable} its
 * environment will be used by this reader.  Otherwise, the reader will initialize and
 * use a {@link StandardEnvironment}. All ApplicationContext implementations are
 * EnvironmentCapable, while normal BeanFactory implementations are not.
 * @param registry the BeanFactory to load bean definitions into,
 * in the form of a BeanDefinitionRegistry
 * @see #setResourceLoader
 * @see #setEnvironment
 */
protected AbstractBeanDefinitionReader(BeanDefinitionRegistry registry) {
    Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
    this.registry = registry;

    // Determine ResourceLoader to use.
    if (this.registry instanceof ResourceLoader) {
        this.resourceLoader = (ResourceLoader) this.registry;
    }
    else {
        this.resourceLoader = new PathMatchingResourcePatternResolver();
    }

    // Inherit Environment if possible
    if (this.registry instanceof EnvironmentCapable) {
        this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
    }
    else {
        this.environment = new StandardEnvironment();
    }
}
项目:data-migration    文件:SqlSessionConfiguration.java   
@Bean
public SqlSessionFactory createSqlSessionFactory() throws Exception {
    SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
    fb.setDataSource(roundRobinDataSouceProxy());
    fb.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
    fb.setTypeAliasesPackage(typeAliasesPackage);
    return fb.getObject();
}
项目:spring-boot-starter-dao    文件:AbstractDataBaseBean.java   
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
        String typeAliasesPackage, Dialect dialect, Configuration configuration) {
    configuration.setDatabaseId(dataSourceName);
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
    bdb.addPropertyValue("configuration", configuration);
    bdb.addPropertyValue("failFast", true);
    bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
    bdb.addPropertyReference("dataSource", dataSourceName);
    bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
    if (!StringUtils.isEmpty(mapperPackage)) {
        try {
            mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
            String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
            String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
            Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
            bdb.addPropertyValue("mapperLocations", resources);
        } catch (Exception e) {
            log.error("初始化失败", e);
            throw new RuntimeException( String.format("SqlSessionFactory 初始化失败  mapperPackage=%s", mapperPackage + ""));
        }
    }
    return bdb.getBeanDefinition();
}
项目:xxpay-master    文件:DruidDataSourceConfig.java   
@Bean
public SqlSessionFactory sqlSessionFactory() 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", "true");
    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:org/xxpay/dal/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
项目:pingguopai    文件:MybatisConfigurer.java   
@Bean
public static 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();
    properties.setProperty("pageSizeZero", "true");//分页尺寸为0时查询所有纪录不再执行分页
    properties.setProperty("reasonable", "true");//页码<=0 查询第一页,页码>=总页数查询最后一页
    properties.setProperty("supportMethodsArguments", "true");//支持通过 Mapper 接口参数来传递分页参数
    pageHelper.setProperties(properties);

    //添加插件
    factory.setPlugins(new Interceptor[]{pageHelper});

    //添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    return factory.getObject();
}
项目:lemon-dubbo-message    文件:MybatisConfiguration.java   
@Bean(name="sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() {
    try {
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sessionFactory.setMapperLocations(resolver.getResources(mapperLocations));

        PageInterceptor pageInterceptor = new MysqlPageInterceptor();
        sessionFactory.setPlugins(new Interceptor[]{pageInterceptor});
        return sessionFactory.getObject();
    } catch (Exception e) {
        logger.warn("Could not confiure mybatis session factory", e);
        return null;
    }
}
项目:springboot-multi-datasource    文件:MyBatisConfig.java   
/**
 * 根据数据源创建SqlSessionFactory
 */
@Bean
public SqlSessionFactory sqlSessionFactory(AbstractRoutingDataSource routingDataSource) throws Exception {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(routingDataSource);// 指定数据源(这个必须有,否则报错)
    // 下边两句仅仅用于*.xml文件,如果整个持久层操作不需要使用到xml文件的话(只用注解就可以搞定),则不加
    factoryBean.setTypeAliasesPackage("com.tangcheng.datasources.aop.model");// 指定基包
    factoryBean.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml"));//
    return factoryBean.getObject();
}
项目:springbootWeb    文件:BusinessDatabaseConfig.java   
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(businessDataSource);
    //mybatis分页
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    PageHelper pageHelper = new PageHelper();
    pageHelper.setProperties(props);
    //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
项目:jaffa-framework    文件:DroolsLoader.java   
/**
 * loads all the Xml files with xml file name in the manager from all the jars
 * where package contains META-INF/*
 */
@PostConstruct
public void loadDrools() {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    try {
        manager.clearDroolsDirectory();
        Resource[] resources = resolver.getResources("classpath*:META-INF/rules/**/*.drl");
        if (resources != null) {
            for (Resource resource : resources) {
                if (resource == null) {
                    continue;
                }
                manager.registerDrool(resource, ContextHelper.getVariationSalience(resource.getURI().toString()));
            }
        }
        manager.createAgents();
    }catch(Exception w){
        w.printStackTrace();
        throw new RuntimeException(w.getCause());

    }
}
项目:jaffa-framework    文件:ResourceLoader.java   
/**
 * loads all the Xml files with xml file name in the manager from all the jars
 * where package contains META-INF/*
  */
@PostConstruct
public void loadXmls() {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = resolver.getResources("classpath*:META-INF/" + manager.getResourceFileName());
        if (resources != null) {
            for (Resource resource : resources) {
                if (resource == null) {
                    continue;
                }
                try {
                    manager.registerResource(resource, ContextHelper.getContextSalience(resource.getURI().toString()),
                            ContextHelper.getVariationSalience(resource.getURI().toString()));
                    managerRepositoryService.add(manager.getClass().getSimpleName(), manager);
                } catch (Exception e) {
                    logger.error("Exception occurred while registering XML " + resource.getURI().toString() + " exception " + e);
                }
            }
        }
    }catch(Exception w){
        throw new RuntimeException(w.getCause());
    }
}
项目:wtem    文件:MybatisConfig.java   
@Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource,
                                               DataSourceProperties properties) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);

        //分页插件
//        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});

        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        bean.setMapperLocations(resolver.getResources(properties.getMybatisMapperLocations()));
        return bean.getObject();
    }
项目:mybatisplus-boot-starter    文件:MybatisPlusProperties.java   
public Resource[] resolveMapperLocations() {
    ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
    List<Resource> resources = new ArrayList<Resource>();
    if (this.mapperLocations != null) {
        for (String mapperLocation : this.mapperLocations) {
            try {
                Resource[] mappers = resourceResolver.getResources(mapperLocation);
                resources.addAll(Arrays.asList(mappers));
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return resources.toArray(new Resource[resources.size()]);
}
项目:mybatis-plus-mini    文件:PackageHelper.java   
/**
   * <p>
   * 别名通配符设置
   * </p>
   * <p>
   * <property name="typeAliasesPackage" value="com.baomidou.*.entity"/>
   * </p>
   *
   * @param typeAliasesPackage 类别名包路径
   * @return
   */
  public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
      ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
      MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
      String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
              + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";

/*
       * 将加载多个绝对匹配的所有Resource
 * 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
 */
      try {
          Set<String> set = new HashSet<>();
          Resource[] resources = resolver.getResources(pkg);
          if (resources != null && resources.length > 0) {
              MetadataReader metadataReader;
              for (Resource resource : resources) {
                  if (resource.isReadable()) {
                      metadataReader = metadataReaderFactory.getMetadataReader(resource);
                      set.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
                  }
              }
          }
          if (!set.isEmpty()) {
              return set.toArray(new String[]{});
          } else {
              throw new MybatisPlusException("not find typeAliasesPackage:" + pkg);
          }
      } catch (Exception e) {
          throw new MybatisPlusException("not find typeAliasesPackage:" + pkg, e);
      }
  }
项目:fly4j    文件:MybatisConfiguration.java   
/**
 * 将mybatis的sqlSessionFactory交给spring管理
 */
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    sessionFactory.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml"));
    sessionFactory.setTypeAliasesPackage("com.fly.**.model");
    return sessionFactory;
}
项目:busi-support    文件:LogDatabaseConfig.java   
@Bean
public SqlSessionFactory logSqlSessionFactory(@Qualifier("logDataSource") DruidDataSource logDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(logDataSource);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
项目:springboot-course    文件:TestDbConfig.java   
@Bean(name = "testSqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("testDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:conf/mybatis/mapper/test/*.xml"));
    return bean.getObject();
}
项目:springboot-course    文件:CourseDbConfig.java   
@Bean(name = "courseSqlSessionFactory")
@Primary
public SqlSessionFactory courseSqlSessionFactory(@Qualifier("courseDataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:conf/mybatis/mapper/course/*.xml"));
    return bean.getObject();
}
项目:rekit-game    文件:Main.java   
/**
 * Set log level for loggers.
 *
 * @param level
 *            the level
 */
private static void setLogLevel(Level level) {
    // Initialize Loggers ...

    GameConf.GAME_LOGGER.setLevel(level);
    Setter.LOGGER.setLevel(level);
    Parser.LOGGER.setLevel(level);
    Logger.getLogger(PathMatchingResourcePatternResolver.class).setLevel(level);

    // This is needed as all loggers add an appender to the rootLogger.
    Logger.getRootLogger().removeAllAppenders();
    BasicConfigurator.configure();
}