properties在spring配置文件中的用法

在spring中引入其他配置文件,使用import导入。

	<import resource="classpath:serviceConfig/mybatis.xml" />
	<import resource="classpath:serviceConfig/mailService.xml" />
	<import resource="classpath:serviceConfig/quartzService.xml" />
	<import resource="classpath:serviceConfig/threadPool.xml" />

properties文件的引入方式分两种。

1.在spring.xml文件中统一引入。

2.在使用该properties文件的的xml配置文件中分别引用。

下面是两种引入方式:

	<bean id="propertyConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:properties/jdbc.properties</value>
				<value>classpath:properties/mail.properties</value>
			</list>
		</property>
	</bean>

                <!--引入属性文件 -->
                <context:property-placeholder
                                location="classpath:properties/mail.properties"
                                ignore-unresolvable="true"/>
                <!--引入属性文件 -->
                <context:property-placeholder
                                location="classpath:properties/jdbc.properties"
                                ignore-unresolvable="true"/>

一定要声明ignore-unresolvable="true",否则tomcat启动会报错。

不过,你也可以把这两个属性文件都写在spirng.xml中,不过这样我更推荐第一种方式了。

另外,对于properties文件还是统一管理会比较好。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值