外在化应用参数的配置 spring <context:property-placeholder location="" />
来源:互联网 发布:重庆seo入门基础教程 编辑:程序博客网 时间:2024/05/01 00:35
1.有些参数在某些阶段中是常量
2.而这些参数在不同阶段之间又往往需要改变
期望:能不能有一种解决方案可以方便我们在一个阶段内不需要频繁书写一个参数的值,而在不同阶段间又可以方便的切换参数配置信息
解决:spring3中提供了一种简便的方式就是context:property-placeholder/元素
只需要在spring的配置文件里添加一句:<context:property-placeholder
#jdbc配置
test.jdbc.driverClassName=com.mysql.jdbc.Driver
test.jdbc.url=jdbc:mysql://localhost:3306/test
test.jdbc.username=root
test.jdbc.password=root
行内#号后面部分为注释
应用:
1.这样一来就可以为spring配置的bean的属性设置值了,比如spring有一个jdbc数据源的类DriverManagerDataSource
在配置文件里这么定义bean:
<beanid="testDataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
</bean>
2.甚至可以将${}这种形式的变量用在spring提供的注解当中,为注解的属性提供值
---------------------------------------------------------
外在化应用参数的配置
在开发企业应用期间,或者在将企业应用部署到生产环境时,应用依赖的很多参数信息往往需要调整,比如LDAP连接、RDBMSJDBC连接信息。对这类信息进行外在化管理显得格外重要。PropertyPlaceholderConfi
PropertyPlaceholderConfi
db.username=scott
db.password=tiger
如下内容摘自propertyplaceholderconfi
- <bean
id= "propertyPlaceholderConfigurer" -
- PropertyPlaceholderConfi
gurer"> -
<property name= -
<list> -
<value>userinfo.properties</value> -
</list> -
</property> - </bean>
-
- <bean
name= "userInfo"class="test.UserInfo"> -
<property name= value= "${db.username}"/> -
<property name= value= "${db.password}"/> - </bean>
通过运行并分析PropertyPlaceholderConfi
- <context:property-placeholder
location= "userinfo.properties"/>
PropertyPlaceholderConfi
- 外在化应用参数的配置 spring <context:property-placeholder location="" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring <context:property-placeholder/> 配置详解
- spring <context:property-placeholder/> 配置详解
- spring <context:property-placeholder/> 配置详解
- spring <context:property-placeholder/> 配置详解
- Spring配置<context:property-placeholder>标签解析
- spring 配置<context:property-placeholder/> 作用
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- 【异常】--spring context:property-placeholder location= 找不到环境配置文件 maven(257)
- Spring的properties解析【context:property-placeholder】
- spring的context:property-placeholder属性
- 浅谈Spring的 context:property-placeholder
- spring的context:property-placeholder属性
- spr.xml中的<context:property-placeholder location=""/>
- 一步一步学android之布局管理器——FrameLayout
- bootmem allocator分析
- KMP算法详解
- 随手笔记之VC++(四)
- 设计模式2 观察者模式
- 外在化应用参数的配置 spring <context:property-placeholder location="" />
- iOS 的 IAP 教程
- Android 桌面插件
- Quagga通信详解
- Android开发点点滴滴——LayoutInflater及inflate方法
- Storyboard全解析-第二部分
- Hibernate 对象的三种状态
- 随手笔记之VC++(六)
- 黑马程序员--05.类加载器--02【抽象类ClassLoader】【JVM加载类的过程】