공부
[spring] service get `spring.profiles.active`
승가비
2023. 10. 18. 11:26
728x90
How do you get current active/default Environment profile programmatically in Spring?
I need to code different logic based on different current Environment profile. How can you get the currently active and default profiles from Spring?
stackoverflow.com
https://devfoxstar.github.io/java/spring-profiles-active/
자바 스프링에서 Profile 정보 가져오기 (Spring Profiles Active)
스프링 프로젝트에서 Profile 설정은 기본입니다. local, dev, qa, stg, prod 등 개발 환경에 맞게 지정해 줍니다. 가끔 지정된 Profile…
devfoxstar.github.io
@Service
class ProfileService(
val environment: Environment
) {
fun get(): Profile? {
return Profile[environment.activeProfiles.firstOrNull()]
}
fun isTest(): Boolean {
return get() != Profile.PRD
}
}
728x90