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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With