0
votes

I have a Spring Boot properties with three properties files: enter image description here

I have a class that uses values defined in application-local.properties file, which I thought would get used because application-properties has `spring.profiles.active=local

When I start up in IntelliJ, I see this in the console logs:

Loaded config file 'file:.../build/resources/main/application.properties' (classpath:/application.properties)
2016-12-18 20:10:17.596 DEBUG 29999 --- [  restartedMain] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file 'file:.../build/resources/main/application-local.properties' (classpath:/application-local.properties)`
Skipped (empty) config file 'file:...build/resources/main/application-local.properties' (classpath:/application-local.properties) for profile local

It says it skipped the empty config file, but when I inspect 'build/resources/main/application-local.properties' then I see the values in there.

However, the following class does not have the properties when I run it from within IntelliJ as a Spring Boot Application. It throws a null pointer because these are null:

@Value("${myapp.ApiKey}")
private String apiKey;

@Value("${myapp.ApiSecret}")
private String apiSecret;

@Value("${myapp.user}")
private String user;

In the Application Configuration I tried using Active Profiles, Program Arguments, and Environment Variables.

However, if I run from the command line as:

java -jar -Dspring.active.profiles=local  build/libs/myjar-0.0.1-SNAPSHOT.jar

then it works just fine. I am sure this was working previously, but not sure if the IntelliJ version was the same. Any tips on how to make the correct version of my application.properties get used?

1

1 Answers

-1
votes

Which spring boot version are you using? If you're using the latest this should be

-Dspring.profiles.active=local

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-set-active-spring-profiles