首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

PropertyPlaceholderConfigurer (spring动态加载property资料)

2013-02-03 
PropertyPlaceholderConfigurer (spring动态加载property文件)PropertyPlaceholderConfigurerbean idco

PropertyPlaceholderConfigurer (spring动态加载property文件)

PropertyPlaceholderConfigurer

<bean id="configBean" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="configBean" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"><value>${driver}</value></property> <property name="url"><value>jdbc:${dbname}</value></property></bean>
而实际的jdbc.propertis文件是jdbc.driverClassName=org.hsqldb.jdbcDriverjdbc.url=jdbc:hsqldb:hsql://production:9002jdbc.username=sajdbc.password=root而jdbc.propertis是怎样引用的呢:
将上边一段配置注册在web.xml中就可以了<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/spring-context.xml</param-value></context-param>当然,不要忘了spring的监听器注册<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>这样,一个简单的数据源就设置完毕了。实际上,PropertyPlaceholderConfigurer起的作用就是将占位符指向的数据库配置信息放在bean中定义的工具。

热点排行