【发布时间】:2014-01-16 21:20:23
【问题描述】:
我使用 Spring 3.2.2 。我想使用 db.properties 文件作为数据库参数
db.properties
db.driver=org.postgresql.Driver
db.url=jdbc:postgresql://localhost:5432/test
db.user=test
db.password=test
弹簧配置
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.password}"/>
</bean>
但我有错误
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [${db.driver}]
谁能帮帮我?
【问题讨论】:
-
您的属性文件位于类路径的顶层,对吧?
-
你如何加载这个 xml 文件?请添加完整的堆栈跟踪。
标签: java spring properties configuration