【Spring】引入properties属性文件
举例:
现在有一个属性文件-c3p0.perperties,如下所示
c3p0.driverClassName=com.mysql.cj.jdbc.Driver c3p0.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 c3p0.username=root c3p0.password=root
将上述属性文件引入applicationContext.xml
引入单个属性文件:
PropertyPlaceholderConfigurer写法
<!-- 引入一个属性文件方法一 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:c3p0.properties"></property> </bean>
context命名空间写法
<!-- 引入一个属性文件方法二 --> <context:property-placeholder location="classpath:druid.properties" />
引入多个属性文件:
<!-- 引入多个属性文件方法一 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:c3p0.properties</value> <value>classpath:druid.properties</value> </list> </property> </bean>

浙公网安备 33010602011771号