Is there a way programmatically to get the current active profile within my bean?
1 Answer
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();
5 Comments
rayman
Thanks. how would you create different property files for different profiles?
Artem Bilan
It's definitely the separate SO question. However you can take a look to Boot docs: docs.spring.io/spring-boot/docs/current/reference/html/…
Girish
Getting environment as null
mangusta
same - getting env as null
Artem Bilan
Perhaps the place you’d like to autowire is not a spring bean. Better to ask a new SO question with more info.