2012-01-11 3 views
0

Je crée mon contexte de ressort à l'intérieur d'une méthode static main avecne sont pas résolus dans le contexte du printemps XML

return new ClassPathXmlApplicationContext("applicationContext.xml"); 

intérieur applicationContext.xml Je suis câblage un de mes haricots avec

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.SingleConnectionDataSource"> 
    <property name="driverClassName"> 
     <value>${db.driverclassname}</value> 
    </property> 
    ... 
</bean> 

I J'ai un fichier .properties sur le chemin de ma classe qui contient la valeur db.driverclassname.

Malheureusement, je me fais l'erreur suivante:

Property 'driverClassName' threw exception; 
    nested exception is java.lang.IllegalStateException: 
     Could not load JDBC driver class [${db.driverclassname}] 

Qu'est-ce que je fais mal? J'utilise le ressort 2.5.5

Répondre

5

Vous n'avez pas besoin d'un PropertyPlaceholderConfigurer?

par exemple.

<bean id="propertyConfigurer"  
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location"> 
     <value>classpath:project.properties</value> 
    </property> 
</bean> 

This article détails utilisation.

0
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>classpath:your.properties</value> 
      </list> 
     </property> 
     <property name="ignoreUnresolvablePlaceholders" value="true"/> 
    </bean> 
Questions connexes