Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine programmatically the current active profile using Spring boot [duplicate]

Is there a way programmatically to get the current active profile within my bean?

like image 443
rayman Avatar asked Oct 08 '22 23:10

rayman


People also ask

What is the default active profile in spring boot?

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.

How do I check my spring boot status?

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 .

How many profile can be defined for a spring application?

In the application. properties we have set the local profile to be active. With the SpringApplicationBuilder's profiles method we add two additional profiles.


1 Answers

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();
like image 135
Artem Bilan Avatar answered Oct 12 '22 14:10

Artem Bilan