Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't work spring.config.additional-location

Tags:

People also ask

How do I set spring config location?

If spring. config. location contains directories (as opposed to files) they should end in / (and will be appended with the names generated from spring.config.name before being loaded). The default search path classpath:,classpath:/config,file:,file:config/ is always used, irrespective of the value of spring.

Can we have multiple configuration files in Spring Boot?

To add different files you can use the spring. config. location properties which takes a comma separated list of property files or file location (directories). The one above will add a directory which will be consulted for application.

Can we have two application properties in Spring Boot?

Spring Boot supports different properties based on the Spring active profile. For example, we can keep two separate files for development and production to run the Spring Boot application.


maven:

<profiles>
    <profile>
        <id>local</id>
        <activation>
           <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <active.spring.profile>local</active.spring.profile>
        </properties>
    </profile>
</profiles>

application.properties:

[email protected]@
spring.config.additional-location=classpath:/profile/application-${spring.profiles.active}.properties

and after this I can't get value from src/main/resources/application-local.properties which contains test.prop=123

@Service
public class TestProps {

    @Value("${test.prop}")
    String testProp;

    @PostConstruct
    void run() {
        System.out.println(testProp);
    }
}

Where is the mistake? or it's a bug?