I've built a J2EE web app using Spring framework on server Tomcat, and my application needs to read some properties (like jdbs connection parameters, paths of folders etc...) which I need to be external. What I mean is that today I put the jar on the server. If in 2 years the connection DB parameters or the folders I want to use are going to change I don't want to redeploy the app, but just change the properties file.
What I have by now is a .properties file in the classpath, and a bean that reads it:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:database.properties"/>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${jdbc.url}" />
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
database.properties:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/cheExport?useSSL=false
jdbc.username=root
jdbc.password=root
How can I accomplish my purpose?
If I remember well there is something I can do in the server xml, where I can specify that a certain folder contains properties file. But then how can I put the things together?
In this post Read properties file outside JAR file is asked the same question, but without using Spring, so I think it's not useful in my case
I also read that it's common to use spring boot in this cases, but I'm using Spring MVC