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.
Go through this link docs.spring.io/spring-boot/docs/1.1.7.RELEASE/reference/html/…
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/