Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발용

[Spring] 어노테이션 기반 설정 본문

개발/WEB

[Spring] 어노테이션 기반 설정

DeP 2017. 1. 24. 16:12

>>pre :: applicationCxt.xml

<context:component-scan base-package="[PACKAGE_NAME]"></context:component-scan>

//어노테이션 붙은 객체들 자동 생성 및 관리

 

 

 

@Component("[REF_KEY]") : 객체 생성

*extends(클래스의 분류, 각 특별한 기능 추가)

@Service : 비즈니스 로직을 처리하는 Service클래스

@Repository : DB연동을 처리하는 DAO클래스

@Controller : 사용자 요청을 제어하는 Controller클래스

 

@Autowired        //Autowired는 component-scan 시 이미 @Component를 설정해놓은 클래스여야 인식

@Qualifier("[REF_KEY]")        //Autowired사용 시 같은 인터페이스라면 무엇을 선택할

@Resource(name="[REF_NAME]")        //Autowired사용 안하고 직접 Component지정

 

 

@PostConstruct ::METHOD : 빈 초기화 과정에서

@PreDestroy ::METHOD : 빈 소멸 과정에서

 

 

*어노테이션과 설정 파일을 섞어 사용할 수 있음.

 

<context:component-scan base-package="[PACKAGE_NAME]"></context:component-scan>

<bean id="[REF_KEY]" class="[CLASS_PATH]"></bean>

 

@Autowired사용 시 해당 클래스에 @Component설정하지 않아도 인식(<bean>)

 

 

'개발 > WEB' 카테고리의 다른 글

[Spring] AOP  (0) 2017.01.24
[Spring] DI(의존성 주입)  (0) 2017.01.24
[Spring] IoC  (0) 2017.01.24
Bean factory  (0) 2017.01.24