@Autowired
메서드 파라미터에 맞는 타입의 빈을 찾아서 자동으로 주입
의존성 주입(Dependency Injection)을 자동화하는 데 사용되는 어노테이션
속성(field), setter method, constructor(생성자)에서 사용된다.
@Component
public class MyClass {
@Autowired
private MyDependency myDependency;
}
@Qualifier
@Autowired와 함께 사용된다.
같은 타입의 빈이 둘 이상인 경우, 에러를 발생시키거나,
@Qualifier 어노테이션을 사용하여 해당 아이디를 적어주어 특정 빈을 선택할 수 있다.
@Component
public class MyComponent {
@Autowired
@Qualifier("myDependencyImpl1")
private MyDependency myDependency;
}
https://standout.tistory.com/476
Annotation - @Component
@Component 개발자가 직접 작성한 Class를 Bean으로 등록하기 위한 Annotation 스프링 MVC에서는 @Component 어노테이션의 특화된 형태인 @Controller, @Service, @Repository 등이 사용된다. @Component public class MyComponent
standout.tistory.com
https://standout.tistory.com/474
Annotation - @Bean @Scope
@Bean 빈은 Spring 컨테이너에서 생성되고 관리되는 객체 개발자가 직접 제어가 불가능한 외부 라이브러리등을 Bean으로 만들려할 때 주로 사용된다. @Configuration public class MyConfiguration { @Bean public MyBe
standout.tistory.com
'JAVA > Spring' 카테고리의 다른 글
Annotation - @RequestMapping (0) | 2023.04.19 |
---|---|
Annotation - @Controller (0) | 2023.04.19 |
Annotation - @Component (0) | 2023.04.19 |
@Component와 @Bean의 차이 (0) | 2023.04.19 |
Annotation - @Bean @Scope (0) | 2023.04.19 |