Loading additional spring profiles from java config

Ruslan Akhundov

Is there any possibility to load aditional spring profiles from java config?

I know that I can use -Dspring.profile.active argument and also add profiles to spring.profiles.include in application.properties.

What I need is to be able to activate profiles from java config. I've created PropertyPlaceholderConfigurer, where I'm adding some custom property files, which also contains property spring.profiles.include, all properties are load and it works ok, but spring doesn't activate any profiles which are inclded using this property.

@Bean
public static PropertyPlaceholderConfigurer ppc() throws IOException {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setLocations(new ClassPathResource("properties/" + property + ".properties"));
    ppc.setIgnoreUnresolvablePlaceholders(true);
    return ppc;
}
Iulian Rosca

The active spring profiles are defined in properties via the following configuration: spring.profiles.active:.

You should list in all the files that you import the profiles that they activate via the above configuration key.

EDIT

First, as per the official documentation the configuration spring.profiles.include is more suitable for unconditionally adding active profiles.

Second, I can assume that PropertyPlaceholderConfigurer is not suitable for what you want to achieve. The official documentation lists the ways you can Externalize Configuration. You can try to use @PropertySource:

@PropertySources({
        @PropertySource(value = "classpath:application.properties"),
        @PropertySource(value = "classpath:other.properties", ignoreResourceNotFound = true)
})
public class Application {
       ...
    }
}

Additionally, you can try to list the other properties files in property spring.config.location inside application.properties as described here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

spring cloud config client not loading configuration from config server

From Dev

Loading Java spark config from yaml file

From Dev

Spring Boot + Spring Cloud Config - How to add more profiles from the Git external configuration

From Dev

Reading Spring profiles from a @controller

From Dev

What is the loading precedence for properties from Spring Cloud Config?

From Dev

NetBeans (Java) - loading additional .java files

From Dev

Remove other profiles from spring configuration file

From Dev

Host not loading from config file

From Dev

Spring XML Config to Java Config

From Dev

Spring XML Config to Java Config

From Dev

OSGi profiles like Spring profiles

From Dev

Spring Security Java Config

From Dev

Spring MVC Java config

From Dev

Spring integration java config

From Dev

Spring Bean with Factory Method from XML to Java Config

From Dev

How to submit file from form using ajax in java config spring?

From Dev

Copy and move a file from SFTP using Java config in Spring Integration

From Dev

Don't work spring.config.additional-location

From Dev

Error loading Groovy config file from JAR

From Dev

uwp loading config from a file at startup

From Dev

Loading config files producing null in Java

From Dev

spring.profiles.active is not working from the command line

From Dev

spring.profiles.active is not working from the command line

From Dev

Loading additional javascript code from firefox add-on content script

From Dev

system property -Dspring.profiles.active not available in spring boot test config in gradle build

From Dev

Spring Java Config and Thymeleaf - Dandelion Datatables config

From Dev

Spring Security XML Config Vs Java Config

From Dev

Spring:xml config convert to java config

From Dev

Additional http requests from config when running karma tests in angularjs

Related Related

  1. 1

    spring cloud config client not loading configuration from config server

  2. 2

    Loading Java spark config from yaml file

  3. 3

    Spring Boot + Spring Cloud Config - How to add more profiles from the Git external configuration

  4. 4

    Reading Spring profiles from a @controller

  5. 5

    What is the loading precedence for properties from Spring Cloud Config?

  6. 6

    NetBeans (Java) - loading additional .java files

  7. 7

    Remove other profiles from spring configuration file

  8. 8

    Host not loading from config file

  9. 9

    Spring XML Config to Java Config

  10. 10

    Spring XML Config to Java Config

  11. 11

    OSGi profiles like Spring profiles

  12. 12

    Spring Security Java Config

  13. 13

    Spring MVC Java config

  14. 14

    Spring integration java config

  15. 15

    Spring Bean with Factory Method from XML to Java Config

  16. 16

    How to submit file from form using ajax in java config spring?

  17. 17

    Copy and move a file from SFTP using Java config in Spring Integration

  18. 18

    Don't work spring.config.additional-location

  19. 19

    Error loading Groovy config file from JAR

  20. 20

    uwp loading config from a file at startup

  21. 21

    Loading config files producing null in Java

  22. 22

    spring.profiles.active is not working from the command line

  23. 23

    spring.profiles.active is not working from the command line

  24. 24

    Loading additional javascript code from firefox add-on content script

  25. 25

    system property -Dspring.profiles.active not available in spring boot test config in gradle build

  26. 26

    Spring Java Config and Thymeleaf - Dandelion Datatables config

  27. 27

    Spring Security XML Config Vs Java Config

  28. 28

    Spring:xml config convert to java config

  29. 29

    Additional http requests from config when running karma tests in angularjs

HotTag

Archive