question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring-Boot 1.4 @ConfigurationProperties location deprecation effects

See original GitHub issue

I’m using a custom PropertySourceLoader to decrypt encryped properties via setting org.springframework.boot.env.PropertySourceLoader factory.

It works for setting in application.properties file. For additional files, I normally use @ConfigurationProperties with setting location and it also works. But with 1.4, location parameter seem to be deprecated (it works for now). When I use @PropertySource to lod prop. file, it just load properties without decrypting them.

How can I make sure that all my property files are processed by org.springframework.boot.env.PropertySourceLoader factory? With the location parameter deprecated, I may need it soon.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ccschneidrcommented, Nov 30, 2016

This solution has two drawbacks compared to the deprecated ConfigurationProperties.locations:

  • it is not regarded in integration tests and thus breaks them
  • it is not possible to add to the list via annotations in other modules/classes As already noted in #6726 it is not very convenient. Should there be an Annotation to contribute to config names?
2reactions
philwebbcommented, Oct 2, 2017

As long as you can get the PropertySource into the Spring Environment @ConfigurationProperties should continue to work.

One option might be to set spring.config.name to a list of the files you want to load:

new SpringApplicationBuilder(Application.class)
    .properties("spring.config.name=application,mine")
    .run(args);

If you want something more specific you could perhaps listen for ApplicationEnvironmentPreparedEvents or write a EnvironmentPostProcessor.

The listener approach would look like this:

new SpringApplicationBuilder(SanityCheckApplication.class)
    .listeners(new LoadAdditionalProperties())
    .run(args);
public class LoadAdditionalProperties implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    private ResourceLoader loader = new DefaultResourceLoader();

    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        try {
            Resource resource = loader.getResource("classpath:mine.properties");
            PropertySource<?> propertySource = new PropertySourcesLoader().load(resource);
            event.getEnvironment().getPropertySources().addLast(propertySource);
        } catch (IOException ex) {
            throw new IllegalStateException(ex);
        }
    }

}

Alternatively, perhaps you could just put all your properties in the application.properties file and do away with the need to load additional files all together.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Core Features - Spring
This section dives into the details of Spring Boot. Here you can learn about the key features that you may want to use...
Read more >
Spring Boot Reference Guide
Change the location of external properties of an application; 70.4. Use 'short' command line arguments; 70.5. Use YAML for external properties; 70.6.
Read more >
Spring Boot Reference Documentation
Try the How-to documents. They provide solutions to the most common questions. Learn the Spring basics. Spring Boot builds on many other Spring...
Read more >
Spring Boot Reference Guide
Change the location of external properties of an application; 63.3. Use 'short' command line arguments; 63.4. Use YAML for external properties; 63.5.
Read more >
“How-to” Guides - Spring
This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins. 1.4. Build an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found