Environment
Spring-boot : 2.1.7.RELEASE OS : Ubuntu 16.04
From this issue #1219 :
After application is loaded, Setting spring.profile.default
value seems it's not working.
You can't change the default profile by declaring it in a config file. It has to be in place before the config files are read.
However, when I pass a value in spring.profiles.default
in application.properties
, the spring-boot console shows
No active profile set, falling back to default profiles: dev
The weird thing is dev
profile wasn't actually activated.
I would expect if the default profile have set it up in application.properties
, the console should display :
No active profile set, falling back to default profiles: default
Comment From: wilkinsona
@Minwoo-Kang Can you please provide a small sample as a zip attached to this issue that reproduces the behaviour that you have described?
Comment From: Minwoo-Kang
@wilkinsona
I attached sample spring-boot application.
As you can see, I've set up server.port=8081
in application.properties
and set up server.port=8088
in application-dev.properties
.
But the console shows
2019-10-18 20:58:40.495 INFO 22562 --- [ restartedMain] c.s.pi.archimonde.ArchimondeApplication : No active profile set, falling back to default profiles: dev 2019-10-18 20:58:41.549 INFO 22562 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
Comment From: wilkinsona
Thank you, @Minwoo-Kang. I've reproduced the problem now.
There are two things that are combining here to create the problem that you're seeing. The first is that, as noted above and in #1219, setting spring.profiles.default
in a configuration file has no effect on config file reading. The second is that, while it has no effect on config file reading, it does still effect the default profile and the dev
profile is, in fact, active.
You can see this for yourself by adding a profile-specific bean to your app:
@Bean
@Profile("dev")
public String profileSpecificBean() {
System.out.println("Creating dev-profile bean");
return "dev-profile";
}
The above will result in Creating dev-profile bean
being output when your app is launched. If you remove spring.profiles.default = dev
from application.properties
it will no longer appear.
In summary, the default profile that is logged is correct but it is confusing as it becomes the default too late for it to affect the loading of profile-specific configuration files. I don't think we'll be able to have spring.profile.default
affect the loading of profile-specific configuration files, but we may be able to reduce the confusion in some other way. For example, perhaps we could log a warning if spring.profile.default
is found in a configuration file.
Comment From: Minwoo-Kang
@wilkinsona Thanks for all great jobs you've done!
I was little bit surprised that the dev
profile was active. I've never thought that I could test creating bean using @Profile
whether dev
profile was activated or not.
But I have one question.
From it does still effect the default profile and the dev profile is, in fact, active.
:
Is this meaning that there are 2 default profile which are default and dev
in the application?
Comment From: wilkinsona
Is this meaning that there are 2 default profile which are default and dev in the application?
I hadn't considered this before. Unfortunately, it does. You can see this for yourself if you rename application-dev.properties
to application-default.properties
. The server's port will then change to 8088
.
Comment From: philwebb
See also #15994
Comment From: mbhave
This is a duplicate of #15994 which has been solved in 2.4.x.