用spring读取properties,出错:
dataSource_config.xml:
<bean id="propertyPlaceHolderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:conf/DB.properties</value>
</list>
</property>
<property name="fileEncoding">
<value>GBK</value>
</property>
</bean>
<bean id="dataSource" lazy-init="true" destroy-method="close"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${it.db.driverClass}"></property>
<property name="jdbcUrl" value="${it.db.jdbcUrl}"></property>
<property name="user" value="${it.db.userName}"></property>
<property name="password" value="${it.db.password}"></property>
<property name="maxIdleTime" value="60"></property>
<property name="idleConnectionTestPeriod" value="60"></property>
</bean>
DB.properties文件:
it.db.jdbcUrl=jdbc:oracle:thin:@192.168.35.207:1521:orcl
it.db.driverClass=oracle.jdbc.driver.OracleDriver
it.db.userName=cnmscfg
it.db.password=ffcsoss
报错信息如下:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in file [G:\MyWorkSpace\ITResourceManager\conf\dataSource_config.xml]: Could not resolve placeholder 'it.db.driverClass'
驱动包什么的都加了,没用properies之前测试过,可以运行,加了之后就出错了,求高手解决
------解决方案--------------------
是这么做的啊。
看看文件在不在指定的地方,如果启动的时候没报错,可能在指定的地方有别的DB.properties文件在那儿。
------解决方案--------------------
- XML code
<bean id="dataSource" lazy-init="true" destroy-method="close"class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${it.db.driverClass}"></property><property name="jdbcUrl" value="${it.db.jdbcUrl}"></property><property name="user" value="${it.db.userName}"></property><property name="password" value="${it.db.password}"></property><property name="maxIdleTime" value="60"></property><property name="idleConnectionTestPeriod" value="60"></property></bean>