spring读取properties配置文件 这样方便于在spring的xml配置中直接用表达式来表示一些不变的变量
如上配置 其中ServletContextPropertyPlaceholderConfigurer是集成了PropertyPlaceholderConfigurer的 下面的配置是一些properties的文件 放在class根目录下 这样在spring的xml配置文件中中就能通过标签使用properties中的配置项了
比如配置数据库就可以使用了
<!-- 数据源定义 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean
class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="searchContextAttributes" value="true" />
<property name="contextOverride" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:test.properties</value>
<value>classpath:test1.properties</value>
</list>
</property>
</bean>
如上配置 其中ServletContextPropertyPlaceholderConfigurer是集成了PropertyPlaceholderConfigurer的 下面的配置是一些properties的文件 放在class根目录下 这样在spring的xml配置文件中中就能通过标签使用properties中的配置项了
比如配置数据库就可以使用了
<!-- 数据源定义 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="${jdbc.initialSize}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
</bean>