Hello,
This is the first bug I've submitted here, so I'm not sure if I've filled everything correctly. I also hope it's not a duplicate, but I haven't found anything related.
Anyway, if you define a profile specific property and enable that profile in .spring-boot-devtools.properties
, then the profile is enabled, but the property value is not actually loaded. A minimum working example:
application.yml:
---
spring.profiles: dev
custom.property: devOn
Application.java:
@SpringBootApplication
public class Application implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Value("${custom.property:devOff}")
private String customProperty;
@Override
public void run(ApplicationArguments args) {
System.out.println("custom.property = " + customProperty);
}
}
.spring-boot-devtools.properties
spring.profiles.active=dev
console:
C:\Users\machart\IdeaProjects\boot-properties-demo>gradlew bootRun
> Task :bootRun
11:47:44.918 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
11:47:44.923 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/,
/spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
11:47:44.923 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/Users/machart/IdeaProjects/boot-properties-demo/build/classes/java/main/, file:/C:/Users/machart/IdeaPro
jects/boot-properties-demo/build/resources/main/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-07-24 11:47:45.402 INFO 9792 --- [ restartedMain] com.example.properties.Application : Starting Application on machart with PID 9792 (C:\Users\machart\IdeaProjects\boot-properties-demo\build\classes\java\main started
by machart in C:\Users\machart\IdeaProjects\boot-properties-demo)
2018-07-24 11:47:45.403 INFO 9792 --- [ restartedMain] com.example.properties.Application : The following profiles are active: dev
2018-07-24 11:47:45.491 INFO 9792 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2de3286a: startup date [Tue Jul 24 11:47:45
CEST 2018]; root of context hierarchy
2018-07-24 11:47:46.545 INFO 9792 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-07-24 11:47:46.580 INFO 9792 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-07-24 11:47:46.600 INFO 9792 --- [ restartedMain] com.example.properties.Application : Started Application in 1.662 seconds (JVM running for 2.179)
custom.property = devOff
2018-07-24 11:47:46.610 INFO 9792 --- [ Thread-8] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2de3286a: startup date [Tue Jul 24 11:47:45 CES
T 2018]; root of context hierarchy
2018-07-24 11:47:46.611 INFO 9792 --- [ Thread-8] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
BUILD SUCCESSFUL in 4s
3 actionable tasks: 1 executed, 2 up-to-date
What is notable in the log above, is that the profile is actually active, but the property value is not loaded, so it falls back to the default devOff
. Of course, if you build the JAR and run that with --spring.profiles.active=dev
, then everything works as expected.
Notes:
* I've been able to reproduce this with both Boot 2.0.3 and 1.5.14.
* This seems to happen even if you use a specific application-dev.yml
or application-dev.properties
file instead the standard one.
* I have tested only the Gradle plugin, not Maven.
Comment From: mbhave
The DevToolsHomePropertiesPostProcessor
processes .spring-boot-devtools.properties
and it runs after the ConfigFileApplicationListener
which adds property sources based on active profiles. I guess this is because we want add the devtools property source first in the list after all the other property sources have been added so that it gets the highest property. But this means that any profiles activated via .spring-boot-devtools.properties
won't get picked up by ConfigFileApplicationListener
.
Let's see if the rest of the team thinks that we should support this.
Comment From: mbhave
We'll document this as a known limitation for now and tackle this as an enhancement in a future release.
Comment From: wilkinsona
I can't find any documentation of the limitation. Assuming I haven't missed it, perhaps we should use #15151 to document the limitation and keep this issue open for a future enhancement?
Comment From: mbhave
Moving this to 2.x which is when we plan to rework a lot of the profile related code.
Comment From: philwebb
We've revisited a lot of the profile property handling in 2.4.x, but we don't see an easy way to support this feature. For the foreseeable future, I think we'll need to leave this as a documented limitation.