Spring40 [Spring] 의존관계 자동 주입 - 3 /애노테이션 생성/빈 조회 List, Map 애노테이션 생성- @Qualifier("mainDiscountPolicy") 처럼 적으면 컴파일시 타입 체크가 안된다. package hello.core.annotation;import org.springframework.beans.factory.annotation.Qualifier;import java.lang.annotation.*;@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})@Retention(RetentionPolicy.RUNTIME)@Inherited@Documented@Qualif.. 2025. 12. 14. [Spring] 의존관계 자동 주입 - 2 롬복조회 빈이 2개 이상 - 문제@Autowried 필드명, @Qualifier, @Primary 롬복 롬복 라이브러리 적용group = 'hello'version = '0.0.1-SNAPSHOT'sourceCompatibility = '11'//lombok 설정 추가 시작configurations { compileOnly { extendsFrom annotationProcessor }}//lombok 설정 추가 끝dependencies { implementation 'org.springframework.boot:spring-boot-starter' //lombok 라이브러리 추가 시작 compileOnly 'org.projectlombok:lombok'.. 2025. 12. 12. [Spring] 옵션 처리 자동 주입 대상을 옵션으로 처리하는 방법이다.- @Autowired(required=false): 자동 주입할 대상이 없으면 메서드를 호출하지 않는다.- @Nullable: 자동 주입할 대상이 없으면 null이 입력된다.- Optional: 자동 주입할 대상이 없으면 Optional.empty가 입력된다. public class AutowiredTest { @Test void AutowiredOption(){ ApplicationContext ac = new AnnotationConfigApplicationContext(TestBean.class); } static class TestBean { @Autowired.. 2025. 12. 9. [Spring] 의존관계 주입 의존관계 주입- 생성자 주입- 수정자 주입 (setter 주입)- 필드 주입- 일반 메서드 주입 생성자 주입- 생성자를 통해 의존 관계를 주입하는 방법이다.- 생성자 호출 시점에서 1번만 호출되는 것이 보장되고 불편, 필수 의존관계에 사용한다. @Componentpublic class OrderServiceImpl implements OrderService { private final MemberRepository memberRepository; private final DiscountPolicy discountPolicy; @Autrowired public OrderServiceImpl (MemberRepository memberRepository, DiscountPolic.. 2025. 12. 7. 이전 1 2 3 4 ··· 10 다음