Manipuler plusieurs .properties
Bonjour,
Etant encore peu habitué avec spring, j'ai quelque soucis avec la manipulation de plusieurs fichiers .properties
J'explique plus en détail le problème :
Le chemin d'accès à un fichier de configuration se trouve dans un autre fichier de configuration (pour être facilement modifié)
config.properties:
Code:
file.properties.name=test/Voiture1.properties
Voiture1.properties:
Code:
1 2 3
| voiture.marque=mercedes
voiture.vitesseMax=150
voiture.couleur=bleu |
Et là les choses deviennent compliqué, dans mon fichier applicationContext.xml je ne sait pas comment recupérer la valeur de file.properties.name directement :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<bean class="org.springframework.core.io.ClassPathResource">
<constructor-arg>
<value>test/config.properties</value>
</constructor-arg>
</bean>
<bean class="org.springframework.core.io.ClassPathResource">
<constructor-arg>
<!-- <value>test/Voiture1.properties</value> -->
<value>${file.properties.name}</value>
</constructor-arg>
</bean>
</list>
</property>
</bean> |
Quand je met directement le chemin du fichier, tout se passe bien, c'est bien '${file.properties.name}' qui n'est pas compris.
voilà l'erreur :
Citation:
26 avr. 2011 14:48:20 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@758fc9: startup date [Tue Apr 26 14:48:20 CEST 2011]; root of context hierarchy
26 avr. 2011 14:48:21 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [test/applicationContext.xml]
26 avr. 2011 14:48:21 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [test/config.properties]
26 avr. 2011 14:48:21 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [${file.properties.name}]
26 avr. 2011 14:48:21 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@14c1103: defining beans [propertyPlaceholder,Voiture1,Voiture2,Garage]; root of factory hierarchy
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [${file.properties.name}] cannot be opened because it does not exist
Exception in thread "main" java.lang.NullPointerException
at test.test.main(test.java:23)
et je vous garantis que mes fichier sont au bon endroit !
TestS2
....|
.....----src
...........|
...........-----test
....................|
....................|-----applicationContext.xml
....................|-----config.properties
....................------Voiture1.properties
Merci d'avance pour votre aide !