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.
分享到:
相关推荐
主要介绍了Spring配置中的"classpath:"与"classpath*:"的区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
本文档介绍了spring中的在classpath中加载配置文件
<description>Spring公共配置文件 <!-- mes 的數據庫 --> <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/> ...
@Component("userService")等价于在spring配置文件中定义一个<bean id="userService"/> @Resource(name="userDAO")将userDA注入进来 写一个拦截器的类 package com.spring.aop; import org.springframework....
本Spring-generator项目基于Java和Apache FreeMarker开发,包含122个文件,包括Java源代码、FXML文件、FTL模板文件、PNG图片、Properties配置文件、CLASSPATH文件、GIT忽略文件、PROJECT文件、LICENSE文件和Markdown...
(2) spring-beans.jar 这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,...
logback框架会默认加载classpath下命名为logback-spring.xml或logback.xml的配置文件。 如果将所有日志都存储在一个文件中,文件大小也随着应用的运行越来越大并且不好排查问题,正确的做法应该是将error日志和其他...
-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org.springframework.web.util....
Spring配置文件 <value>classpath*:app.properties 设置环境变量或JVM启动参数 环境变量方式 export config.server=localhost:6379 export config.environment=dev JVM启动参数方式 -Dconfig.server=...
classpath*: 前缀 4.7.2.3. 其他关于通配符的说明 4.7.3. FileSystemResource 提示 5. 校验,数据绑定,BeanWrapper,与属性编辑器 5.1. 简介 5.2. 使用Spring的Validator接口进行校验 5.3. 从错误代码到错误信息 ...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...
在xml配置文件中,这样加载properties文件 <bean id="propertyConfigurer" class="com.better517na.propertiesComponent.business.ExtendedPropertyPlaceholderConfigurer"> <value>classpath:...
spring管理struts的action的代码 从类路径下加载spring的配置文件, 多个配置文件可以用逗号和空格区分 * classpath: 关键字特指类路径下加载
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装载...
配置文件特定的配置文件 26.记录 26.1.日志格式 26.2.控制台输出 26.2.1.彩色编码输出 26.3.文件输出 26.4.日志级别 26.5.日志组 26.6.自定义日志配置 26.7.Logback Extensions 26.7....
在idea中打开applicationContext.xml,它是一个spring配置文件,你会看到“classpath*:com/yongpoliu/bean/internal/**/module-*.xml” 将 applicationContext.xml 拖到另一个目录,然后您将看到该想法所做的文件...
这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,引入spring-core.jar及...
3 导入配置文件,将如下配置文件导入到src下面 3.1 修改generatorConfig.xml文件,这个是mybatis的逆向工程,修改数据库名,用户名,密码,对应的包名,对应的项目。如图 3.2 修改jdbc.properits文件, 3.3 log...
web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: ...