티스토리 뷰
3-4 (Dependency Injection) - Annotation 기반 설정
Annotation 설정
우선 XML 설정 파일에 Namespace 부터 설정함.
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemalLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/contxt/springcontext-3.0.xsd">
</beans>
Component Scan
<beans …… />
<context:component-scan base-package="com.multicampus.biz" />
</beans>
<bean />과 관련된 Annotation
<bean /> 으로 명시적 등록하는 대신 @Component 같은 Annotation 사용하여 등록함.
component scan에 의해 Bean이 자동 등록됨.
@Component("userService")
public class UserServiceImpl implements UserService {
}
Dependency Injection 설정
@Autowired
Spring에서 지원하는 Annotation(Spring 2.5 이상)
객체 이름 = 클래스명의 첫글자만 소문자로 바꾼 것
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserDAO userDAO;
}
Setter 메서드나 생성자를 작성할 필요가 없음
@Qualifier
주입하려는 객체명과 클래스명이 다른 경우나 모호한 경우 사용
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
@Qualifier("userDAOJDBC")
private UserDAO userDAO;
}
@Resource
Bean Name을 지정하여 Dependency를 Injection 하는 경우 사용함.
JSR-250 표준 Annotation
특정 프레임워크에 종속적이지 않음.
@Service("userService")
public class UserServiceImpl implements UserService {
@Resource(name="userDAO")
private UserDAO userDAO;
}
'It' 카테고리의 다른 글
명령어 세트 (0) | 2022.08.16 |
---|---|
명령어 파이프라이닝 (0) | 2022.08.16 |
명령어 실행 (0) | 2022.08.16 |
Spring AOP 4-1 AOP (0) | 2022.08.15 |
Dependency Injection 3-3 Dependency Injection (0) | 2022.08.15 |
- Total
- Today
- Yesterday
- 실검
- 러브 라이프 토렌트
- 영화소개
- 실시간검색어
- 러브 라이프 예고편
- 오늘의사건
- 하나님의 마음 다시보기
- 러브 라이프 무료보기
- 영화순위
- 하나님의 마음 바로보기
- 러브 라이프 정식자막
- 옛날영화
- 추천영화
- Movie
- 하나님의 마음 한글자막
- 하나님의 마음 정식자막
- 영화
- 오늘의이슈
- 하나님의 마음 예고편
- 러브 라이프 다운로드
- 외국영화
- 러브 라이프 한글자막
- 하나님의 마음 토렌트
- 하나님의 마음 다운로드
- 하나님의 마음 무료보기
- 박스오피스
- 하나님의 마음 마그넷
- 하나님의 마음 고화질
- 영화추천
- 한국영화
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |