PropertyPlaceholderConfigurer
Spring的框架中为提供了一个BeanFactoryPostProcessor的实体类别: org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
可以将一些动态参数,移出至.properties中,如此的安排可以让XML定义系统相关设定(不常变动),而.properties可以作为客户根据实际自定义一些相关参数。(如不同人数据库的不同密码)
applicationConfig.xml
<beans>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/db.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver">
<value>${driver}</value>
</property>
<property name="driverUrl">
<value>${driverUrl}</value>
</property>
<property name="user">
<value>${user}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
<property name="alias">
<value>spring</value>
</property>
<property name="houseKeepingSleepTime">
<value>90000</value>
</property>
<property name="prototypeCount">
<value>5</value>
</property>
<property name="maximumConnectionCount">
<value>100</value>
</property>
<property name="minimumConnectionCount">
<value>10</value>
</property>
<property name="trace">
<value>true</value>
</property>
<property name="verbose">
<value>true</value>
</property>
</bean>
</beans>
db.properties
driver=com.mysql.jdbc.Driver
driverUrl=jdbc:mysql://localhost/securedoc?user=root&password=sqladmin&useUnicode=true&characterEncoding=GBK
user=root
password=sqladmin
分享到:
相关推荐
1. **BeanPostProcessor**:这是Spring容器中Bean的后置处理器接口,它允许在Bean实例化之后执行自定义的操作。Spring自身已经实现了多个BeanPostProcessor,例如: - `ApplicationContextAwareProcessor`:用于...
### Spring学习笔记核心知识点解析 #### 一、消息资源配置(`Messagesource`) 在Spring框架中,`Messagesource`接口被用来支持国际化(i18n),它提供了一种方式来根据不同的区域设置(locale)加载不同的资源...
Spring允许与`xxx.properties`格式的配置文件结合使用,首先在XML中注册配置文件,如`<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">`,然后在其他bean中引用这些属性值,...
通过`PropertyPlaceholderConfigurer` Bean,可以加载`.properties`文件并引用其中的值,这样在其他Bean的配置中就可以动态引用这些值,增强了配置的灵活性和可复用性。 总的来说,Spring框架通过其强大的IoC和AOP...
本文将基于“spring-framework原始阅读笔记”展开,深入探讨Spring的核心组件,包括容器实现、属性名解析、AOP(面向切面编程)以及SpringMVC的细节。 首先,让我们从Spring的核心——容器开始。Spring容器是整个...
本篇笔记主要介绍了一个具体的AJAX配置示例,它涉及了Spring框架、Direct Web Remoting (DWR) 和Hibernate等技术的应用。下面将详细解析这些配置代码的关键部分及其作用。 #### 二、web.xml配置分析 **1. Spring上...
描述:"这是我学习过程中积累的学习笔记,希望对大家有用" 标签:"c3p0" 知识点详述: C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC连接池的特性,如:自动重连、自动创建数据库对象等。在...