189

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

0

1 Answer 1

356

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();
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. how would you create different property files for different profiles?
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/…
Getting environment as null
same - getting env as null
Perhaps the place you’d like to autowire is not a spring bean. Better to ask a new SO question with more info.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.