`
tracyhuyan
  • 浏览: 80311 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

在自定义的配置文件使用 place holder

 
阅读更多

Spring使用place holder

 

spring 使用PropertyPlaceholderConfigurer和PropertyOverrideConfigurer对象,which 实现了

 

BeanFactoryPostProcessor接口,在spring的配置文件里面<beans>里面可以使用 ${properties_name}来引用在外

 

部配置文件里面定义的变量。

 

好处是可以外部配置参数,在部署一些依赖环境的参数,比如JDBC连接,server ip等数据时比较方便在一个文件里面统一配置。

 

 

使用配置xml的方式 :

方式一:

<context:property-placeholder 
          ignore-resource-not-found="true"
          ignore-unresolvable="true"
          system-properties-mode="OVERRIDE"
          location="classpath:db_config.properties"/>

 

方式二:

    <bean id="propertyPlaceholderConfigurer"   
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="locations">  
            <list>  
                <value>db_config.properties</value>  
            </list>  
        </property>  
    </bean>  
     
    <bean name="jdbcTemplate" class="test.JdbcTemplate">  
      <property name="username" value="${db.username}"/>  
      <property name="password" value="${db.password}"/>  
    </bean> 

 

自定义配置文件使用place holder


TODO...


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics