티스토리 뷰

728x90

https://stackoverflow.com/questions/9267799/how-do-you-get-current-active-default-environment-profile-programmatically-in-sp/77262475#77262475

 

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
댓글