jdbc.properties文件中有信息如下:
username=rooturl=jdbc:mysql://localhost:3306/qw?characterEncoding=utf8driver=com.mysql.jdbc.Driverpwd=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>
用法同上。