1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
datasource.driver=org.mysql.driver.Driver
datasource.url=jdbc://mysql:localhost/maBase
datasource.username=dbUser
datasource.password=dbPassword
Il est possible de récupérer ces informations sous forme de variables dans le fichier de configuration de Spring en ajoutant un Bean :
<bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:com/developpez/hikage/properties/datasource.properties</value>
</property>
</bean>
Ensuite, pour accèder aux variables il suffit de les encadrer dans ${ } :
<bean id="datasource" class="com.developpez.hikage.Datasource">
<property name="urlConnection" value="${datasource.url}"/>
<property name="drivers" value="${datasource.drivers}"/>
<property name="username" value="${datasource.username}"/>
<property name="password" value="${datasource.password}"/>
</bean> |
Partager