I'm trying to build a war file that knows to look in a specific path for a spring boot application.properties. For example, when running in a linux environment,
I'd like my maven build to some how build that app so that it knows to look at the following location:
/etc/projects/application.properties
To be clear, I want to avoid setting system or command line properties. I want to wire into spring the location of the file and have application server and os be unaware of how spring does that. Is this possible?
You can pass -Dspring.config.location=/etc/projects/application.properties
as part of the JAVA_OPTS
to Tomcat.
//edit:
I was sure that above will work, but..:)
according to documentation (here) you can create config
directory next to your war/jar file, and create application.properties
file there. It will be loaded.
Ive tested that by cloning this repo. Edit HelloController
class in initial
project:
@RestController
public class HelloController {
@Value("${test.property}")
private String testProperty;
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot! Test property value="+testProperty;
}
}
build jar with maven:
mvn clean package
create config
directory, add our property there, run app:
cd target
mkdir config
echo "test.property=Value from external config" >> config/application.properties
java -jar gs-spring-boot-0.1.0.jar
goto localhost:8080
- value from external property file should be there :)
Ofcourse if you really have to store your files on /etc/projects/
then you can create symlinks inside config
dir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With