spring 读取properties的两种方法

来源:互联网 发布:php产品管理系统 编辑:程序博客网 时间:2024/05/17 23:05
1.在配置文件中配置PropertyPlaceholderConfigurer
  1. <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  2.   <property name="locations" value="classpath:com/foo/jdbc.properties"/>
  3. </bean>
 
然后在需要的地方直接以下方式引用:
  1. <property name="url" value="${jdbc.url}"/>
 
2.在配置文件中加入
beans的命名空间声明如下:
  1. <beans xmlns="http://www.springframework.org/schema/beans" 
  2.      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
  3.      xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 
  4.      xsi:schemaLocation="http://www.springframework.org/schema/beans 
  5.             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
  6.             http://www.springframework.org/schema/context 
  7.             http://www.springframework.org/schema/context/spring-context-3.0.xsd 
  8.             http://www.springframework.org/schema/aop 
  9.             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
  10.             http://www.springframework.org/schema/tx 
  11.             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
 
用到了
  1. xmlns:context=http://www.springframework.org/schema/context
配置如下:
  1. <context:property-placeholder location="dbconf.properties"/>
原创粉丝点击