applicationContext.xml读取properties中属性

前端之家收集整理的这篇文章主要介绍了applicationContext.xml读取properties中属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

载入方式一:

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beans
  3. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  4. http://www.springframework.org/schema/jee
  5. http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
  6. <context:property-placeholderlocation="classpath:uc.properties"/>
  7. </beans>

载入方式二:

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beans
  3. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  4. http://www.springframework.org/schema/jee
  5. http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
  6. <beanid="configBean"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  7. <propertyname="locations">
  8. <value>uc.properties</value>
  9. </property>
  10. </bean>
  11. </beans>

使用方式:

  1. <value>${name}</value>
  2. 或者
  3. <propertyname="driverClass"value="${driverClass}"/>

如果有多个properties文件的情况

  1. <beanid="configBean"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  2. <propertyname="locations">
  3. <list>
  4. <value>hello.properties</value>
  5. <value>welcome.properties</value>
  6. <value>other.properties</value>
  7. </list>
  8. </property>
  9. </bean>

猜你在找的XML相关文章