1. 기본 값 설정을 위한 @Value 어노테이션
@Component
public class NewlecExam implements Exam{
@Value("20")
private int kor;
@Value("20")
private int eng;
@Value("30")
private int math;
}
위와 같이 작상된 Component로 객체를 생성하면 해당 필드에 입력한 값이 들어간 상태로 생성된다.
2. <context:component-scan>
위 명령어는 애플리케이션 컨텍스트에 등록된 빈들의 어노테이션들이 적용될 수 있게 한다.
그리고 어노테이션이 설정된 새로운 빈들을 찾는 스캔도 할 수 있다.
3. 적용 가능한 어노테이션
@Component
|------ @Controller ------ |------ @RequestMapping
|------ @Service |------ @GetMapping
|------ @Repository |------ @...
1) Controller : 사용자의 입출력을 담당
2) Service : 사용자의 요구사항에 맞는 서비스를 제공
3) Repository : 데이터를 제공
=> 모두 Component로 똑같은 기능을 담당하지만, 사용하는 방법에 따라 세가지를 구분하여 사용한다.
'뉴렉쳐 스프링 프레임워크 정리' 카테고리의 다른 글
[17강] XML Configuration을 Java Configuration으로 변경하기 (0) | 2023.06.11 |
---|---|
[15강] 어노테이션을 이용한 객체 생성 (0) | 2023.06.10 |
[14강] @Autowired의 위치와 Required 옵션 (0) | 2023.06.10 |
[13강] @Autowired의 동작방식 이해와 @Qualifier 사용하기 (0) | 2023.06.10 |