Reputation: 3717
I am setting the logging.file.name
in application.properties
file which I want to pass as command line argument. Is it possible?
The reason is I am trying to run multiple jar files from a single application and I want to display logs of each application run at a single location.
Upvotes: 1
Views: 4117
Reputation: 265211
Spring Boot provides several options to externalize configuration.
Spring Boot uses a very particular
PropertySource
order that is designed to allow sensible overriding of values. Properties are considered in the following order (with values from lower items overriding earlier ones):
- Default properties (specified by setting
SpringApplication.setDefaultProperties
).@PropertySource
annotations on your@Configuration
classes. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such aslogging.*
andspring.main.*
which are read before refresh begins.- Config data (such as
application.properties
files).- A
RandomValuePropertySource
that has properties only inrandom.*
.- OS environment variables.
- Java System properties (
System.getProperties()
).- JNDI attributes from
java:comp/env
.ServletContext
init parameters.ServletConfig
init parameters.- Properties from
SPRING_APPLICATION_JSON
(inline JSON embedded in an environment variable or system property).- Command line arguments.
properties
attribute on your tests. Available on@SpringBootTest
and the test annotations for testing a particular slice of your application.@TestPropertySource
annotations on your tests.- Devtools global settings properties in the
$HOME/.config/spring-boot
directory when devtools is active.
So you should be possible to override the values defined in your application.properties
by setting environment variables, Java system properties, or command line arguments:
export LOGGING_FILE_NAME=yourfile.txt
-Dlogging.file.name=yourfile.txt
--logging.file.name=yourfile.txt
Upvotes: 2