spring中context:property-placeholder/元素
来源:互联网 发布:淘宝店铺分为几种类型 编辑:程序博客网 时间:2024/06/05 14:19
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:
<bean id="testDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
</bean>
2.甚至可以将${ }这种形式的变量用在spring提供的注解当中,为注解的属性提供值
---------------------------------------------------------
外在化应用参数的配置
在开发企业应用期间,或者在将企业应用部署到生产环境时,应用依赖的很多参数信息往往需要调整,比如LDAP连接、RDBMS JDBC连接信息。对这类信息进行外在化管理显得格外重要。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/元素
- 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/元素
- 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/元素
- spring中context:property-placeholder/元素
- spring中context:property-placeholder/元素
- spring中context:property-placeholder/元素
- CSS 加载新方式
- win8.1 opnet14.5 一段时间后不用license老是失效解决方法
- IIC静默模式下读取数据
- 使用 Docker 搭建 JavaWeb环境(Tomcat,jdk)
- nchan-nginx
- spring中context:property-placeholder/元素
- handler的post 方法
- 如何在mac上搭建cocos2d 环境
- Android 5.0 Camera2新接口
- windows7中文企业版安装英文语言包
- 利用VBA对提取excel中字母、数字进行提取
- Linux下Redis开机自启(Centos)
- 安卓刷第三方Rom
- 纱窗