Spring Boot and several external configuration files

I have several property files that I want to load from a classpath. There is one default set in the /src/main/resources section, which is part of myapp.jar . My springcontext expects files to be in the classpath. those.

 <util:properties id="Job1Props" location="classpath:job1.properties"></util:properties> <util:properties id="Job2Props" location="classpath:job2.properties"></util:properties> 

I also need to override these properties with an external set. I have an external configuration folder in cwd . According to spring, the boot doc configuration folder should be in the classpath. But this is not clear from the document if it will only cancel applicaiton.properties from there or all the properties in config.

When I tested it, only application.properties will be retrieved, and the rest of the properties will still be retrieved from /src/main/resources . I tried to provide them as a comma-separated list on spring.config.location , but the default set is still not reevaluated.

How to make mulitiple external configuration files override standard ones?

As a workaround, I currently used app.config.location (an application property), which I provide through the command line. iee

 java -jar myapp.jar app.config.location=file:./config 

and I changed my applicationcontext to

 <util:properties id="Job2Props" location="{app.config.location}/job2.properties"></util:properties> 

And this is how I do the separation between file and classpath during application loading.
edits:

 //psuedo code if (StringUtils.isBlank(app.config.location)) { System.setProperty(APP_CONFIG_LOCATION, "classpath:"); } 

I would really like not to use the aforementioned workaround and spring to override all external configuration files in the classpath, as is done for the application.properties file.

+79
java spring spring-boot config
Sep 15 '14 at 19:47
source share
12 answers

When using Spring Boot, properties are loaded in the following order (see External configuration in the Spring Boot reference manual).

  1. Command line arguments.
  2. Java System Properties (System.getProperties ()).
  3. OS environment variables.
  4. Java JNDI Attributes: comp / env
  5. RandomValuePropertySource, which has properties only in random order. *.
  6. Application properties outside your packaged jar (application.properties, including YAML and profile options).
  7. Application properties packaged inside your jar (application.properties, including YAML and profile options).
  8. @PropertySource annotations for your @Configuration classes.
  9. Default properties (set using SpringApplication.setDefaultProperties).

When resolving properties (i.e., @Value("${myprop}") resolving is done in the reverse order (starting at 9).

To add different files, you can use spring.config.location properties that accept a comma-separated list of property files or the location of files (directories).

 -Dspring.config.location=your/config/dir/ 

The above will add the directory that application.properties files will access.

 -Dspring.config.location=classpath:job1.properties,classpath:job2.properties 

This will add 2 properties file to the downloaded files.

Configuration files and locations are loaded by default before the files specified in spring.config.location , specified additionally, which means that the latter will always override the properties specified in the previous ones. (See also this section of the Spring Boot reference manual).

If spring.config.location contains directories (as opposed to files), they must end in / (and will be added with the names generated from spring.config.name before loading). The default search path classpath:,classpath: /config,file:,file:config/ always used, regardless of the value of spring.config.location . That way, you can set the default values ​​for your application in application.properties (or any other spring.config.name name that you select using spring.config.name ) and override it at runtime with another file, storing the values ​​by by default.

UPDATE: Since the behavior of spring.config.location now overrides the default value instead of adding to it. You need to use spring.config.additional-location to save the default values. This is a change in behavior from 1.x to 2.x

+100
Sep 16 '14 at 6:53
source share

When loading Spring, spring.config.location works, just provide the property files separated by commas.

see below code

 @PropertySource(ignoreResourceNotFound=true,value="classpath:jdbc-${spring.profiles.active}.properties") public class DBConfig{ @Value("${jdbc.host}") private String jdbcHostName; } } 

You can install the standard version of jdbc.properties inside the application. External versions can be installed as follows:

 java -jar target/myapp.jar --spring.config.location=classpath:file:///C:/Apps/springtest/jdbc.properties,classpath:file:///C:/Apps/springtest/jdbc-dev.properties 

Based on the profile value set using the spring.profiles.active property, the value jdbc.host will be selected. Therefore, when (on the windows)

 set spring.profiles.active=dev 

jdbc.host will take values ​​from jdbc-dev.properties.

for

 set spring.profiles.active=default 

jdbc.host will take values ​​from jdbc.properties.

+25
May 16 '16 at
source share

Take a look at PropertyPlaceholderConfigurer, I find it more understandable than annotation.

eg.

 @Configuration public class PropertiesConfiguration { @Bean public PropertyPlaceholderConfigurer properties() { final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); // ppc.setIgnoreUnresolvablePlaceholders(true); ppc.setIgnoreResourceNotFound(true); final List<Resource> resourceLst = new ArrayList<Resource>(); resourceLst.add(new ClassPathResource("myapp_base.properties")); resourceLst.add(new FileSystemResource("/etc/myapp/overriding.propertie")); resourceLst.add(new ClassPathResource("myapp_test.properties")); resourceLst.add(new ClassPathResource("myapp_developer_overrides.properties")); // for Developer debugging. ppc.setLocations(resourceLst.toArray(new Resource[]{})); return ppc; } 
+20
Sep 17 '14 at 7:28
source share

Spring boot 1.X and Spring Boot 2.X do not provide the same parameters and behavior for Externalized Configuration .

A very good answer by M. Deinum relates to the features of Spring Boot 1.
I will be updating for Spring Boot 2 here.

Sources and order of environmental properties

Spring Boot 2 uses a very specific PropertySource order, which is designed to intelligently override values. Properties are considered in the following order:

  • Properties of global Devtools settings in your home directory (~ / .spring-boot-devtools.properties when devtools is active).

  • @TestPropertySource annotations on your tests.

  • @SpringBootTest#properties attribute of property annotation in your tests. Command line arguments.

  • Properties from SPRING_APPLICATION_JSON (embedded JSON embedded in an environment variable or system property).

  • ServletConfig initialization options.

  • ServletContext initialization options.

  • JNDI attributes from java:comp/env .

  • Java System Properties ( System.getProperties() ).

  • OS environment variables.

  • RandomValuePropertySource which has properties only in random order. *.

  • Profile-specific application properties outside your packaged jar ( application-{profile}.properties and YAML options).

  • Profile-specific application properties packaged inside your jar ( application-{profile}.properties and YAML options).

  • Application properties outside your packaged jar ( application.properties and YAML options).

  • Application properties packaged inside your jar ( application.properties and YAML options).

  • @PropertySource for your @Configuration classes. Default properties (set by setting SpringApplication.setDefaultProperties ).

To specify external properties files, these parameters should interest you:

  • Profile-specific application properties outside your packaged jar ( application-{profile}.properties and YAML options).

  • Application properties outside your packaged jar ( application.properties and YAML options).

  • @PropertySource for your @Configuration classes. Default properties (set by setting SpringApplication.setDefaultProperties ).

You can use only one of these 3 options or combine them according to your requirements.
For example, for very simple cases, it’s enough to use only profile-specific properties, but in other cases you can use both profile-specific properties, default properties, and @PropertySource .

Default location for application.properties files

About application.properties files (and their variants) By default, Spring loads them and adds their properties to the environment in the following order:

  • A / config subdirectory of the current directory

  • Current directory

  • Classpath / config package

  • Class root

Top priorities are so literal:
classpath:/,classpath: /config/,file:./,file:./config/ .

How to use property files with specific names?

The default location is not always sufficient: a default location, such as the default file name ( application.properties ), may not be suitable. In addition, as in the OP question, you may need to specify several configuration files other than application.properties (and its variant).
So spring.config.name will not be enough.

In this case, you must spring.config.location explicit location using the spring.config.location environment (which is a comma-separated list of directory locations or file paths).
To be free in the file name template, add a list of file paths above the directory list.
For example, do this:

 java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties 

This method is most detailed when a folder is simply specified, but it is also a way to very accurately specify our configuration files and clearly document efficiently used properties.

spring.config.location now replaces default locations instead of adding to them

In Spring Boot 1, the spring.config.location argument adds the specified locations to the Spring environment.
But from Spring Boot 2, spring.config.location replaces the default locations used by Spring with the specified locations in the Spring environment, as documented .

When configurable custom locations are configured using spring.config.location , they replace the default locations. For example, if spring.config.location configured with the value classpath: /custom-config/ , file:./custom-config/ , the search order becomes the following:

  1. file:./custom-config/

  2. classpath:custom-config/

spring.config.location is now a way to ensure that any application.properties file must be explicitly specified.
For UAR JARs that should not package application.properties files, this is pretty good.

To preserve the old spring.config.location behavior when using Spring Boot 2, you can use the new spring.config.additional-location instead of spring.config.location which still adds locations, as stated in the documentation :

In addition, when custom configuration locations are configured using spring.config.additional-location , they are used in addition to the default locations.




On practice

So, suppose that, as in the OP question, you have 2 external properties files to specify and 1 properties file included in the uber jar.

To use only the configuration files you specify:

 -Dspring.config.location=classpath:/job1.properties,classpath:/job2.properties,classpath:/applications.properties 

To add configuration files to them in default locations:

 -Dspring.config.additional-location=classpath:/job1.properties,classpath:/job2.properties 

classpath: /applications.properties in the last example is not required, since the default locations have this and that the default locations here are not overwritten, but expanded.

+8
Aug 17 '18 at 7:06
source share

I had the same problem. I wanted to be able to overwrite the internal configuration file at startup with an external file similar to the Spring Boot application.properties detection. In my case, this is the user.properties file in which my applications are stored.

My requirements:

Download the file from the following locations (in that order)

  • Class path
  • A / config subdirectory of the current directory.
  • Current directory
  • From the directory or location of the file specified by the command-line option at startup

I came up with the following solution:

 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.PathResource; import org.springframework.core.io.Resource; import java.io.IOException; import java.util.Properties; import static java.util.Arrays.stream; @Configuration public class PropertiesConfig { private static final Logger LOG = LoggerFactory.getLogger(PropertiesConfig.class); private final static String PROPERTIES_FILENAME = "user.properties"; @Value("${properties.location:}") private String propertiesLocation; @Bean Properties userProperties() throws IOException { final Resource[] possiblePropertiesResources = { new ClassPathResource(PROPERTIES_FILENAME), new PathResource("config/" + PROPERTIES_FILENAME), new PathResource(PROPERTIES_FILENAME), new PathResource(getCustomPath()) }; // Find the last existing properties location to emulate spring boot application.properties discovery final Resource propertiesResource = stream(possiblePropertiesResources) .filter(Resource::exists) .reduce((previous, current) -> current) .get(); final Properties userProperties = new Properties(); userProperties.load(propertiesResource.getInputStream()); LOG.info("Using {} as user resource", propertiesResource); return userProperties; } private String getCustomPath() { return propertiesLocation.endsWith(".properties") ? propertiesLocation : propertiesLocation + PROPERTIES_FILENAME; } } 

Now the application uses the classpath resource, but also checks for the availability of the resource in other places. The last resource will be selected and used. I can run my application with java -jar myapp.jar --properties.location = / directory / myproperties.properties to use the location of the properties that floats on my boat.

An important detail here: use the empty string as the default value for the .location property in the @Value annotation to avoid errors when the property is not set.

Convention for .location property: Use the directory or path to the property file as property.location.

If you want to override only certain properties, the PropertiesFactoryBean property with setIgnoreResourceNotFound (true) can be used with an array of resources set as locations.

I am sure that this solution can be expanded to handle multiple files ...

EDIT

Here is my solution for multiple files :) As before, this can be combined with PropertiesFactoryBean.

 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.PathResource; import org.springframework.core.io.Resource; import java.io.IOException; import java.util.Map; import java.util.Properties; import static java.util.Arrays.stream; import static java.util.stream.Collectors.toMap; @Configuration class PropertiesConfig { private final static Logger LOG = LoggerFactory.getLogger(PropertiesConfig.class); private final static String[] PROPERTIES_FILENAMES = {"job1.properties", "job2.properties", "job3.properties"}; @Value("${properties.location:}") private String propertiesLocation; @Bean Map<String, Properties> myProperties() { return stream(PROPERTIES_FILENAMES) .collect(toMap(filename -> filename, this::loadProperties)); } private Properties loadProperties(final String filename) { final Resource[] possiblePropertiesResources = { new ClassPathResource(filename), new PathResource("config/" + filename), new PathResource(filename), new PathResource(getCustomPath(filename)) }; final Resource resource = stream(possiblePropertiesResources) .filter(Resource::exists) .reduce((previous, current) -> current) .get(); final Properties properties = new Properties(); try { properties.load(resource.getInputStream()); } catch(final IOException exception) { throw new RuntimeException(exception); } LOG.info("Using {} as user resource", resource); return properties; } private String getCustomPath(final String filename) { return propertiesLocation.endsWith(".properties") ? propertiesLocation : propertiesLocation + filename; } } 
+6
Mar 13 '15 at 19:11
source share

spring boot allows us to write different profiles for writing in different environments, for example, we can have separate properties files for production, qa and local environments

application-local.properties configuration file according to my local machine

 spring.profiles.active=local spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=users spring.data.mongodb.username=humble_freak spring.data.mongodb.password=freakone spring.rabbitmq.host=localhost spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.rabbitmq.port=5672 rabbitmq.publish=true 

Similarly, we can write application-prod.properties and application-qa.properties as many properties files we want

then write some scripts to launch the application for different environments, for example,

 mvn spring-boot:run -Drun.profiles=local mvn spring-boot:run -Drun.profiles=qa mvn spring-boot:run -Drun.profiles=prod 
+6
Nov 02 '17 at 12:24
source share

I had a similar problem and finally figured out the reason: the application.properties file had the wrong property attributes and rwx. Therefore, when tomcat was running, the application.properties file was in the right place, but belonged to another user:

 $ chmod 766 application.properties $ chown tomcat application.properties 
+5
Feb 19 '15 at 14:53
source share

this is a simple approach using spring boot

TestClass.java

 @Configuration @Profile("one") @PropertySource("file:/{selected location}/app.properties") public class TestClass { @Autowired Environment env; @Bean public boolean test() { System.out.println(env.getProperty("test.one")); return true; } } 

context app.properties in your chosen location

 test.one = 1234 

your spring application to download

 @SpringBootApplication public class TestApplication { public static void main(String[] args) { SpringApplication.run(testApplication.class, args); } } 

and predefined application.properties context

 spring.profiles.active = one 

you can write as many configuration classes as you want and enable / disable them by setting spring.profiles.active = profile name / names {separated by commas}

since you can see that spring is loading, you just need to get familiar someday, it's worth mentioning that you can also use @Value in your fields

 @Value("${test.one}") String str; 
+5
Apr 27 '16 at 17:52
source share

I found this to be a useful role model:

 @RunWith(SpringRunner) @SpringBootTest(classes = [ TestConfiguration, MyApplication ], properties = [ "spring.config.name=application-MyTest_LowerImportance,application-MyTest_MostImportant" ,"debug=true", "trace=true" ] ) 

Here we redefine the use of "application.yml" to use "application-MyTest_LowerImportance.yml" as well as "application-MyTest_MostImportant.yml"
(Spring will also search for .properties files)

As an added bonus, debugging and tracing options in a separate line are also included so you can comment them out if necessary;]

Debugging / tracing is incredibly useful as Spring displays the names of all the files that it downloads and those that it tries to load.
You will see these lines in the console at runtime:

 TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_MostImportant.properties' (file:./config/application-MyTest_MostImportant.properties) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_MostImportant.xml' (file:./config/application-MyTest_MostImportant.xml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_MostImportant.yml' (file:./config/application-MyTest_MostImportant.yml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_MostImportant.yaml' (file:./config/application-MyTest_MostImportant.yaml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_LowerImportance.properties' (file:./config/application-MyTest_LowerImportance.properties) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_LowerImportance.xml' (file:./config/application-MyTest_LowerImportance.xml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_LowerImportance.yml' (file:./config/application-MyTest_LowerImportance.yml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_LowerImportance.yaml' (file:./config/application-MyTest_LowerImportance.yaml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_MostImportant.properties' (file:./application-MyTest_MostImportant.properties) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_MostImportant.xml' (file:./application-MyTest_MostImportant.xml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_MostImportant.yml' (file:./application-MyTest_MostImportant.yml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_MostImportant.yaml' (file:./application-MyTest_MostImportant.yaml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_LowerImportance.properties' (file:./application-MyTest_LowerImportance.properties) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_LowerImportance.xml' (file:./application-MyTest_LowerImportance.xml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_LowerImportance.yml' (file:./application-MyTest_LowerImportance.yml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./application-MyTest_LowerImportance.yaml' (file:./application-MyTest_LowerImportance.yaml) resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_MostImportant.properties' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_MostImportant.xml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_MostImportant.yml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_MostImportant.yaml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_LowerImportance.properties' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_LowerImportance.xml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_LowerImportance.yml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/config/application-MyTest_LowerImportance.yaml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_MostImportant.properties' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_MostImportant.xml' resource not found DEBUG 93941 --- [ main] osbccConfigFileApplicationListener : Loaded config file 'file:/Users/xxx/dev/myproject/target/test-classes/application-MyTest_MostImportant.yml' (classpath:/application-MyTest_MostImportant.yml) TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_MostImportant.yaml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_LowerImportance.properties' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_LowerImportance.xml' resource not found DEBUG 93941 --- [ main] osbccConfigFileApplicationListener : Loaded config file 'file:/Users/xxx/dev/myproject/target/test-classes/application-MyTest_LowerImportance.yml' (classpath:/application-MyTest_LowerImportance.yml) TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'classpath:/application-MyTest_LowerImportance.yaml' resource not found TRACE 93941 --- [ main] osbccConfigFileApplicationListener : Skipped config file 'file:./config/application-MyTest_MostImportant-test.properties' (file:./config/application-MyTest_MostImportant-test.properties) resource not found 
0
08 . '18 16:14
source share

@mxsb, , yml.

-dev.yml , yml, -dev.yml. . " : /test/test.yml,classpath: /test2/test.yml"

 application: properties: locations: "classpath*:/**/*-dev.yml" 

.

 @Configuration public class PropertiesConfig { private final static Logger LOG = LoggerFactory.getLogger(PropertiesConfig.class); @Value("${application.properties.locations}") private String[] locations; @Autowired private ResourceLoader rl; @Bean Map<String, Properties> myProperties() { return stream(locations) .collect(toMap(filename -> filename, this::loadProperties)); } private Properties loadProperties(final String filename) { YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); try { final Resource[] possiblePropertiesResources = ResourcePatternUtils.getResourcePatternResolver(rl).getResources(filename); final Properties properties = new Properties(); stream(possiblePropertiesResources) .filter(Resource::exists) .map(resource1 -> { try { return loader.load(resource1.getFilename(), resource1); } catch (IOException e) { throw new RuntimeException(e); } }).flatMap(l -> l.stream()) .forEach(propertySource -> { Map source = ((MapPropertySource) propertySource).getSource(); properties.putAll(source); }); return properties; } catch (IOException e) { throw new RuntimeException(e); } } } 

, , yml , Spring bean-.

 config - application.yml - application-dev.yml - application-prod.yml management - management-dev.yml - management-prod.yml 

...

 @Component public class PropertiesConfigurer extends PropertySourcesPlaceholderConfigurer implements EnvironmentAware, InitializingBean { private final static Logger LOG = LoggerFactory.getLogger(PropertiesConfigurer.class); private String[] locations; @Autowired private ResourceLoader rl; private Environment environment; @Override public void setEnvironment(Environment environment) { // save off Environment for later use this.environment = environment; super.setEnvironment(environment); } @Override public void afterPropertiesSet() throws Exception { // Copy property sources to Environment MutablePropertySources envPropSources = ((ConfigurableEnvironment) environment).getPropertySources(); envPropSources.forEach(propertySource -> { if (propertySource.containsProperty("application.properties.locations")) { locations = ((String) propertySource.getProperty("application.properties.locations")).split(","); stream(locations).forEach(filename -> loadProperties(filename).forEach(source ->{ envPropSources.addFirst(source); })); } }); } private List<PropertySource> loadProperties(final String filename) { YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); try { final Resource[] possiblePropertiesResources = ResourcePatternUtils.getResourcePatternResolver(rl).getResources(filename); final Properties properties = new Properties(); return stream(possiblePropertiesResources) .filter(Resource::exists) .map(resource1 -> { try { return loader.load(resource1.getFilename(), resource1); } catch (IOException e) { throw new RuntimeException(e); } }).flatMap(l -> l.stream()) .collect(Collectors.toList()); } catch (IOException e) { throw new RuntimeException(e); } } 

}

0
18 . '18 10:25
source share

, application.properties, , . , , "", , "application-override.properties" /tmp,

 java -jar yourApp.jar --spring.profiles.active="override" --spring.config.location="file:/tmp/,classpath:/" 

, spring.config.location, . , classpat, .

JAR "application-override.properties" ,

 java -jar yourApp.jar --spring.profiles.active="override" 

Spring Boot

0
12 . '18 15:28
source share

, . ,

Dev Env: Windows 10, Java: 1.8.0_25, Spring Boot: 2.0.3.RELEASE, Spring: 5.0.7.RELEASE

, " ". , . , , "--spring.config.additional-location" . , war.

: https://github.com/gselvara/spring-boot-property-demo/tree/master

-one
27 . '18 23:04
source share



All Articles