`
san_yun
  • 浏览: 2662243 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

PathMatchingResourcePatternResolver

 
阅读更多
PathMatchingResourcePatternResolver是一个通配符的Resource查找器,包括:
/WEB-INF/*-context.xml
com/mycompany/**/applicationContext.xml
file:C:/some/path/*-context.xml
classpath:com/mycompany/**/applicationContext.xml

如果要处理一个目录下的文件就可以下面的代码:
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        
        Resource[] resources = resolver.getResources("classpath:com/you/atlas/webx/context/*.class");
        
        System.out.println(resources[0].getURL());
echo:file:/home/work/branche/springtest/target/classes/com/you/atlas/webx/context/WebxContextLoader.class



spring SqlMapClientFactoryBean提供了一个setMappingLocations方法支持“/myApp/*-map.xml”,不用哭逼的增加一个sqlpmap就在xml文件加一条啊!
分享到:
评论
1 楼 href2008 2015-07-27  
你好,问下,同样的location地址。为什么main执行可以读出来。但是打包到tomcat下就不行了?是为什么呢?

相关推荐

    spring源代码

    import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @SuppressWarnings("all") public class ...

    Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件2

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { Resource[] resources = resolver.getResources("classpath:**/applicationContext-*.xml"); for (Resource...

    spring boot中配置mybatis热加载.zip

    setMapperLocations(new PathMatchingResourcePatternResolver().getResources(myBatisConfig.getMapperLocations())); return super.getObject(); } } ``` 这里的`MyBatisConfig`是一个配置类,用于存放XML映射...

    mybatisMapped报错 Statements collection does not contain value for

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factory.setMapperLocations(resolver.getResources("classpath*:cn/microvideo/ws/mapper_oracle/*.xml")); ...

    08次课 Redis-04 在SpringBoot中使用.doc

    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml")); return sessionFactory.getObject(); } @Bean public CacheManager cacheManager...

    spring-boot-starter-mybatis-spring-boot-2.1.1.zip

    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); factoryBean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); return factoryBean.getObject(); } } `...

    ruanjian-java-220212.pdf

    `PathMatchingResourcePatternResolver`帮助找到指定路径的资源,然后将加载的配置添加到环境的属性源列表中。 3. **`StandardEnvironment`** `StandardEnvironment`是Spring Environment的实现,用于存储和管理...

    mybatisplus常用控制类和分类查询查用代码

    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return factoryBean.getObject(); } @Bean public MybatisPlusInterceptor ...

    让Hibernate同时支持xml和注解两种映射方式

    这可能涉及到使用`PathMatchingResourcePatternResolver`来解析资源路径。 5. 在初始化过程中,根据配置确定是处理注解还是XML映射,或者两者都处理。 6. 不要忘记在Spring配置文件中使用这个新的`...

    spring3.x的读书笔记-2

    ResourceLoader接口定义了资源加载的策略,而PathMatchingResourcePatternResolver是其一个实现,用于解析包含通配符的资源路径。 接下来,我们讨论BeanFactory和ApplicationContext。BeanFactory是Spring框架的...

    SpringBoot多数据源配置(方式一:配置多个mapper扫描不同的包路径实现多数据源配置).docx

    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); // Mapper XML 文件位置 return factoryBean.getObject(); } @Bean public ...

    spring集成mybatis示例

    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return factoryBean.getObject(); } } ``` 7. **启用自动扫描Mapper** 添加`@...

    spring boot中配置mybatis热加载相关文件

    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(properties.getMapperLocations())); return factoryBean.getObject(); } } ``` 4. 创建`MapperRefresh.java`类,...

    springboot之mybatis多数据源最简解决方案.docx

    bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/test1/*.xml")); return bean.getObject(); } @Bean(name = "test1TransactionManager") @...

    springboot逆向生成mybatis

    factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return factoryBean.getObject(); } @Bean public DataSource dataSource() { // ...

    Mybatis-plus整合Swagger

    factory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml")); return factory.getObject(); } } ``` 接着,配置Swagger。创建一个Docket Bean,定义API的...

    SPRING API 2.0.CHM

    All Classes ...PathMatchingResourcePatternResolver PatternMatchUtils PerformanceMonitorInterceptor PerformanceMonitorListener Perl5RegexpMethodPointcut PermissionDeniedDataAccessException ...

    Java笔记-通过反射获取注解及Spring中获取某包下的所有class文件

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); MetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory(resolver); String packageSearchPath =...

    JSP 中Spring的Resource类读写中文Properties实例代码

    `PathMatchingResourcePatternResolver`是一个具体的`ResourcePatternResolver`实现,它能够解析Ant风格的路径模式,并返回匹配的`Resource`对象数组。一旦获取到`Resource`对象,就可以通过`getInputStream()`读取`...

    spring boot启动时加载外部配置文件的方法

    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); propertiesFactoryBean.setIgnoreResourceNotFound(true); Resource fileSystemResource = resolver.getResource("file:/opt/...

Global site tag (gtag.js) - Google Analytics