Spring @PropertySource for devel and for production

I am confused about the possibility of using different configuration parameters for devel and for production.
Let’s make an example, I have a file with a lot of properties for devel and I use it in a Spring configuration bean like this:

@Configuration
@EnableTransactionManagement
@PropertySource({"classpath:persistance-erp.properties"})
@EnableJpaRepositories(basePackages = "it.fox.dafne.db.erp.dao", 
                       entityManagerFactoryRef = "erpEntityManager", 
                       transactionManagerRef = "erpTransactionManager")
public class PersistenceErpConfiguration {

// lot of code

}

the file persistance-erp.properties is in the resources directory in my IDE. When I package the code for production and I install the App in the server I would like to instantiate the same bean but with a file from /etc/myApp/persistance-erp.properties and not use any more the one in the classpath.

Which is the proper way to have a bean that in devel use the file in the resource directory and on production use the one in /etc ?

I have tried to add

@PropertySource(value = "file:/etc/dafne/persistance-erp.properties", ignoreResourceNotFound = true)

but the property are summed up, I would like to use one file OR the other not to sum up the properties.

Thanks,
S.

  • Remove hardcoded value from property source. Use application-erp.properties as file name. Provide the profile name in command line. For example – java -jar myproject.jar -Dspring.profiles.active=erp –spring.config.additional-location=/absoulte/path/

    – 

Leave a Comment