spring中context:property-placeholder/元素
来源:互联网 发布:k近邻算法代码 matlab 编辑:程序博客网 时间:2024/05/19 04:55
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/元素
- pycharm out of memory的解决方法
- Oracle知识点
- 使用opencv staticlib静态库
- python数据如何保存到excel中
- 老僧长谈设计模式-10-桥接模式
- spring中context:property-placeholder/元素
- web.xml配置详解
- Huffman编码
- 第16周项目1-验证算法(1)直接插入排序
- 第13周项目3 Dijkstra算法的验证
- Unity3D 贪食蛇小游戏Demo[3D版]-准备工作(一)
- 第九周项目1-猴子选大王数组版
- 【第十五周 项目2—用哈希法组织关键字】
- 第十五周 项目3 B-树的基本操作