`

spring配置中classpath和classpath*的区别

阅读更多
在spring配置文件里,可以用classpath:前缀,来从classpath中加载资源

比如在src下有一个jdbc.properties的文件,可以用如下方法加载:
<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:jdbc.properties</value>
			</list>
		</property>
	</bean>

对于打包在jar包中的资源,也可以用同样的方式:
<import resource="classpath:META-INF/cxf/cxf.xml" />


另外一种很像的方式,是使用classpath*:前缀,比如
<property name="mappingLocations">
			<list>
				<value>classpath*:/hibernate/*.hbm.xml</value>
			</list>
		</property>


classpath:与classpath*:的区别在于,前者只会从第一个classpath中加载,而后者会从所有的classpath中加载

如果要加载的资源,不在当前ClassLoader的路径里,那么用classpath:前缀是找不到的,这种情况下就需要使用classpath*:前缀

另一种情况下,在多个classpath中存在同名资源,都需要加载,那么用classpath:只会加载第一个,这种情况下也需要用classpath*:前缀

可想而知,用classpath*:需要遍历所有的classpath,所以加载速度是很慢的,因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*
分享到:
评论

相关推荐

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

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

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

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

    Spring通过在classpath自动扫描方式把组件纳入spring容器中管理

    NULL 博文链接:https://huangminwen.iteye.com/blog/1486843

    spring boot加载资源路径配置和classpath问题解决

    主要介绍了spring boot加载资源路径配置和classpath问题解决,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    Spring2.5 自动扫描classpath

    NULL 博文链接:https://hahalzb.iteye.com/blog/690802

    Spring的web配置

    springmvc的资源配置:Spring 刷新Introspector防止内存泄露,Spring MVC配置;Character Encoding filter; &lt;param-name&gt;contextConfigLocation &lt;param-value&gt;classpath*:applicationContext-*.xml ...

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

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

    Spring AOP配置源码

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

    spring jar 包详解

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

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

    12.5.1. iBATIS 1.x和2.x的概览与区别 12.5.2. iBATIS SQL Maps 1.x 12.5.2.1. 创建SqlMap 12.5.2.2. 使用 SqlMapTemplate 和 SqlMapDaoSupport 12.5.3. iBATIS SQL Maps 2.x 12.5.3.1. 创建SqlMapClient 12.5.3.2....

    springboot+mybatis+内置tomcat示例.rar

    spring.thymeleaf.prefix=classpath:/templates/ #spring.thymeleaf.suffix=.jsp spring.thymeleaf.cache=false #mybatis 配置 mybatis.mapper-locations=classpath:mapping/*Mapper.xml mybatis.type-...

    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高版本对ibatis的支持

    最近想在最新的Spring5.0中集成ibatis(不是mybatis),发现已经不在支持SqlmapClientTemplate和SqlmapClientFactoryBean,于是搞了这个工具jar来进行支持如下配置 &lt;bean id="sqlMapClient" class="org.spring...

    spring applicationContext 配置文件

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

    Spring_Framework_ API_5.0.5 (CHM格式)

    Spring5 版本的候选版本已经在 classpath 和 modulepath 上支持 Java9 了。 GA版本中你可以期待良好的 JDK9 支持。 3. 使用 JDK8 特性 获取免费Spring 5 新特性视频详解可以群:554355695 在 Spring4.3 之前,...

    spring-boot-starter-mybatis:Spring Boot MyBatis入门

    春天启动启动器mybatis 这是MyBatis的非官方Spring Boot Starter 与官方相反,它遵循其他Spring Boot数据存储库的约定并实现适当...spring.mybatis.mapperLocations =classpath*:mapper/**/*.xml # mappers file spri

    spring源代码

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

    Spring零配置Demo---JavaConfig

    采用注解配置SpringMVC,有SpringSecurity,Dao,Controller,Servlet等的样例,部分代码: public void onStartup(ServletContext servletContext) throws ServletException { //日志文件配置 servletContext....

    Spring Framewor开发手册

    2. Spring 2.0和 2.5的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 新的bean作用域 2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)驱动配置 2.2.5. 在classpath中自动搜索组件 2.3. ...

Global site tag (gtag.js) - Google Analytics