Is there a way programmatically to get the current active profile within my bean?
The default profile is always active. Spring Boot loads all properties in application. yml into the default profile. We could rename the configuration file to application-default.
On system level - you can run your project as a service, which is documented in the Official documentation - Deployments. Then you can query the application status service myapp status .
In the application. properties we have set the local profile to be active. With the SpringApplicationBuilder's profiles method we add two additional profiles.
It doesn't matter is your app Boot or just raw Spring. There is just enough to inject org.springframework.core.env.Environment
to your bean.
@Autowired
private Environment environment;
....
this.environment.getActiveProfiles();
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