• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

@profile 여러개 설정방법

24.01.28 16:36 작성 24.01.28 16:36 수정 조회수 351

1

안녕하세요

@Profile 어노테이션 사용할때 여러개의 환경일때 빈을 가져오고싶다하면

@Profile(“test1”, “test2”), @Profile(“test1|test2”)

위의 예시중에 어떤방식이 맞는건지 그리고 어떻게 가져오는건지 내부를 확인하고싶으면 어디를 확인하면 좋을지 질문드립니다

답변 1

답변을 작성해보세요.

0

David님의 프로필

David

2024.01.28

안녕하세요. 초보개발님, 공식 서포터즈 David입니다.

  1. @Profile 애노테이션 자바 파일을 열어보면 알 수 있습니다.

value가 String 배열로 선언되어 있습니다. 여러 개의 프로파일을 명시하고 싶으시면

@Profile({"A", "B"})와 같이 작성하시면 됩니다.

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(ProfileCondition.class)
public @interface Profile {

	/**
	 * The set of profiles for which the annotated component should be registered.
	 */
	String[] value();

}

  1. ProfileCondition 클래스의 matches 메서드부터 살펴보시면 됩니다.

감사합니다.

채널톡 아이콘