`
butterluo
  • 浏览: 53052 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

spring 配置文件中的 classpath*

阅读更多
0,
There is special support for retrieving multiple class path resources with the same name, via the "classpath*" prefix. For example, "classpath*:/beans.xml" will find all beans.xml files in the class path, be it in "classes" directories or in JAR files. This is particularly useful for auto-detecting config files.

1,
Hmm..After reading PathMatchingResourcePatternResolver, it looks like classpath* prefix should work with wildcards in mutliple JARs. My test showed it worked for contexts in WEB/classes, but not with a mix in WEB-INF/classes, and some in JARs in WEB-INF/lib. Maybe a bug?

Just updating this post...
OK - just to clarify after feedback from Juergen. classpath*: and wildcards do work, but not from the root directory within JARs. So for application contexts in the classpath at:

/com/company/applicationContext.xml
/com/company/applicationContext-ds.xml

If they're in WEB-INF/classes the following will work:
classpath*:**/applicationContext*.xml

If they're in a JAR in WEB-INF/lib the following will work:
classpath*:/com/**/applicationContext*.xml

2,
When you use 'classpath:' for an Ant style wildcard search, Spring uses a single classpath directory for the search. The documentation is vague, but it seems the directory returned will be the first one provided by ClassLoader.getResources(""). In our case, it returned the '/target/test-classes' directory that contains applicationTest.xml and our test classes, instead of '/target/classes' which contains application.xml and all the *.hbm.xml files.

Using the 'classpath*:' prefix fixes the problem. It indicates that the resource loader should look in all directories on the classpath, so making this change solved our problem. Apparently Spring maintains both prefixes because limitations in the Classloader (at the specification level) make it difficult to search for resources in the classpath root when performing wildcard searches across all classpath directories. This suggest it might be good practice to always create a directory to contain resources you might otherwise want to put in the classpath root and always use the 'claspath*:' prefix.

分享到:
评论
1 楼 yanwu 2009-01-06  
好东西

相关推荐

    浅析Spring配置中的classpath:与classpath*:的区别

    主要介绍了Spring配置中的"classpath:"与"classpath*:"的区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

    Spring中使用classpath加载配置文件浅析

    本文档介绍了spring中的在classpath中加载配置文件

    加载jar包中的spring配置文件

    spring applicationContext 配置文件

    <description>Spring公共配置文件 <!-- mes 的數據庫 --> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/> ...

    Spring AOP配置源码

    @Component("userService")等价于在spring配置文件中定义一个<bean id="userService"/> @Resource(name="userDAO")将userDA注入进来 写一个拦截器的类 package com.spring.aop; import org.springframework....

    基于Java和Apache FreeMarker的Spring-generator图形界面Spring代码生成器设计源码

    本Spring-generator项目基于Java和Apache FreeMarker开发,包含122个文件,包括Java源代码、FXML文件、FTL模板文件、PNG图片、Properties配置文件、CLASSPATH文件、GIT忽略文件、PROJECT文件、LICENSE文件和Markdown...

    spring jar 包详解

    (2) spring-beans.jar 这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,...

    Logback配置文件根据 LEVEL级别将日志分类保存到不同文件.docx

    logback框架会默认加载classpath下命名为logback-spring.xml或logback.xml的配置文件。 如果将所有日志都存储在一个文件中,文件大小也随着应用的运行越来越大并且不好排查问题,正确的做法应该是将error日志和其他...

    CXF WebService整合Spring示例工程代码demo

    -- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org.springframework.web.util....

    基于Redis的分布式配置管理中心.zip

    Spring配置文件 <value>classpath*:app.properties 设置环境变量或JVM启动参数 环境变量方式 export config.server=localhost:6379 export config.environment=dev JVM启动参数方式 -Dconfig.server=...

    Spring-Reference_zh_CN(Spring中文参考手册)

    classpath*: 前缀 4.7.2.3. 其他关于通配符的说明 4.7.3. FileSystemResource 提示 5. 校验,数据绑定,BeanWrapper,与属性编辑器 5.1. 简介 5.2. 使用Spring的Validator接口进行校验 5.3. 从错误代码到错误信息 ...

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...

    Spring 自定义注解注入properties文件的值jar包

    在xml配置文件中,这样加载properties文件 <bean id="propertyConfigurer" class="com.better517na.propertiesComponent.business.ExtendedPropertyPlaceholderConfigurer"> <value>classpath:...

    spring管理struts的action的代码

    spring管理struts的action的代码 从类路径下加载spring的配置文件, 多个配置文件可以用逗号和空格区分 * classpath: 关键字特指类路径下加载

    Spring中文帮助文档

    2.2.5. 在classpath中自动搜索组件 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的支持 2.3.3. 对bean命名pointcut( bean name pointcut element)的支持 2.3.4. 对AspectJ装载...

    Spring Boot中文文档.rar

    配置文件特定的配置文件 26.记录 26.1.日志格式 26.2.控制台输出 26.2.1.彩色编码输出 26.3.文件输出 26.4.日志级别 26.5.日志组 26.6.自定义日志配置 26.7.Logback Extensions 26.7....

    idea-wildcard:描述intellij idea中移动通配符spring config问题的示例项目

    在idea中打开applicationContext.xml,它是一个spring配置文件,你会看到“classpath*:com/yongpoliu/bean/internal/**/module-*.xml” 将 applicationContext.xml 拖到另一个目录,然后您将看到该想法所做的文件...

    Spring 2.5 jar 所有开发包及完整文档及项目开发实例

    这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,引入spring-core.jar及...

    JAVA Spring框架实现登陆查询 完整搭建框架方法的word文档 包含mysql文件

    3 导入配置文件,将如下配置文件导入到src下面 3.1 修改generatorConfig.xml文件,这个是mybatis的逆向工程,修改数据库名,用户名,密码,对应的包名,对应的项目。如图 3.2 修改jdbc.properits文件, 3.3 log...

    springweb3.0MVC注解(附实例)

    web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: ...

Global site tag (gtag.js) - Google Analytics