jdbc.properties文件中有信息如下:
username=root
url=jdbc:mysql://localhost:3306/qw?characterEncoding=utf8
driver=com.mysql.jdbc.Driver
pwd=123456789在Spring配置文件中引入properties文件有两种写法:
1、直接使用context:property-placeholder>标签,把jdbc.properties文件路径写进去就可以了。如:
<context:property-placeholder location="classpath:jdbc.properties"/>用法是:${...}
如果我要取url的数据,直接写成这样:${url}
2、配置成bean的形式,如:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<!--可以配置多个资源文件 -->
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>用法同上。
本文介绍了如何在Spring配置文件中引入properties文件,并提供了两种实现方式:使用context:property-placeholder标签直接引入和配置为bean形式。同时展示了具体的XML配置示例。
9656

被折叠的 条评论
为什么被折叠?



