Thursday, June 4, 2009

Spring 2.5.x setting properties file in context xml

There are situations we need to configure some values defined in Spring context XML files via another properties file.

In spring 2.5.x, it can be done as follows:

Example Properties file:

persistenceUnitName=mysqlPunit


Spring context file snippet:
<context:property-placeholder location="classpath:config.properties"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="${dbPersistentUnit}"/>
</bean>




The 'persistenceUnitName' will be changed to 'mysqlPunit' when the context is loaded in java.

No comments:

Post a Comment