171

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

pixel
  • 24,905
  • 36
  • 149
  • 251
rayman
  • 20,786
  • 45
  • 148
  • 246

1 Answers1

328

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();
pixel
  • 24,905
  • 36
  • 149
  • 251
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118