2014-01-16 85 views
0

我使用Spring 3.2.2。我想使用DB db.properties文件中的參數Spring 3.2.2屬性佔位符不工作

db.properties

db.driver=org.postgresql.Driver 
db.url=jdbc:postgresql://localhost:5432/test 
db.user=test 
db.password=test 

spring配置

<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}] 

任何人可以幫助我嗎?

+0

您的屬性文件位於類路徑的頂層,對嗎? – Vidya

+0

如何喲加載這個XML文件?請添加完整的堆棧跟蹤。 –

+0

我使用spring MVC – javagc

回答

1

嘗試定義你的屬性文件在春季爲:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <value>classpath:db.properties</value> 
     </property> 
</bean> 

,比訪問它在相同的方式,你沒有。

+0

我使用Mybatis,當我使用mybatis-spring 1.0.1時它正在工作,但是當我使用1.1.1版本時沒有工作 – javagc