I'm building a war package which will be deployed into a web container using spring boot. And I want to put the spring boot config file outside the war file. My idea is to put the file location in System Property and specify it from spring boot's default config file in directory resources, something like this:
spring.config.additional-location: ${encryption.home}/
or
spring.config.location: ${encryption.home}/
But neither works, seems it doesn't load the external config file. How can I do this? Or whether there's another approach for me to put spring boot config file (not in classpath) outside a WAR file.
Related
I have a Spring boot application and an application.yml file. Now in order to read values from the application.yml I am using #Value annotation and it works fine.
The issue comes, when I try to read the application.yml file from a jar file. I have a jar file, and it is added as a dependency in the my spring boot application, now if I try to read application.yml file from the jar file using #Value I don't get anything.
Is there a way I can read the application.yml using the jar file dependencies?
You could put the application.yml file outside the resources folder of your spring project and read it through any jar.
First boot your spring boot app with this command:
java -jar -Dspring.config.location=<path-to-file> myBootApp.jar
And you can read your file through your other jar by using a YAML library. There are
several libraries that you could choose from.
You could also check this article for more info on reading the properties from outside your spring boot app.
I created a spring boot project and wanted to externalize log4j.xml, application property file and jar ,so that I can create a bat file and run the spring boot application through this command
java -Dlog4j.configuration=file:/temp/log4j.xml -jar temp/ltstatus.jar -Dspring.config.location=temp/application.properties
Replace temp as your folder path
I'm using Spring Boot Profiles to pull in different properties depending on the environment specified (default and localhost). They work as expected but both the application.properties AND application-localhost.properties get pulled into the WAR file.
Is there a way to create the WAR file with only the properties file for the active profile? I would like to configure it so if active profile is set to default then application-localhost.properties is NOT packaged in the WAR file.
i created a new spring boot application.
For development i use the default "appilcation.propperties" for my configuration.
But for production i want to have a external configuration file, because this application will run on multiple tomcats. So i want to have a "application.properties" on every tomcat.
EG:
"SERVER/TOMCAT1_ROOT/conf/application.propperties"
"SERVER/TOMCAT2_ROOT/conf/application.propperties"
Now i thought i can add this path dynamicly in my default "application.propperties":
spring.config.additional-location=file:${CATALINA_HOME}/conf/application.properties
But this line is not parsable. So is there any way to include a path dynamicly?
When spring boot,mvc war file has been deployed in stand alone tomcat, application.yml is located at $CATALINA_HOME/webapps/demo/WEB-INF/classes/application.yml
Can I move the same to $CATALINA_HOME/conf/Catalina/localhost/dmo.yml ?
In general without using spring boot my configuration file will be located at $CATALINA_HOME/webapps/demo/META-INF/context.xml which can be moved to $CATALINA_HOME/conf/Catalina/localhost/demo.xml
Is the same is possible for application.yml also? Then How?
This will help while re-deploying my config file will be backed-up automatically.
You can change the default location for application.properties/yml files using spring.config.location and spring.config.name properties and their corresponding environment variables. The easiest way is to set the SPRING_CONFIG_LOCATION environment variable:
export SPRING_CONFIG_LOCATION=$CATALINA_HOME/conf/Catalina/localhost/dmo.yml
Check out spring boot documentation for more info on loading property files.