VO Class 에서는 DI가 안되는 건가요?
- 작성자 :
- 김*환
- 작성일 :
- 2012-05-21 19:46:42
- 조회수 :
- 1,865
- 구분 :
- 실행환경
- 진행상태 :
- 완료
Q
@Component(" XXXVO ")
public class XXXVO{
@Resource(name = "propertiesService")
protected EgovPropertyService propertyService;
public PaginationInfo getPaginationInfo() {
if(propertyService==null){
System.out.println("propertyService : " + "null");
}else
{
paginationInfo.setRecordCountPerPage(propertyService.getInt("pageUnit"));
paginationInfo.setPageSize(propertyService.getInt("pageSize"));
}
return paginationInfo;
}
}
이런식으로 VO 클래스에서 Injection 하게 설정을 했는데요.
막상 propertyService 를 사용 할려구 하면 NullPoint 가 납니다.
어떻게 해야 될까요.?
답변좀 부탁드립니다~!!
component-scan 에서는 base-package 로 지정이 되어 있습니다.
public class XXXVO{
@Resource(name = "propertiesService")
protected EgovPropertyService propertyService;
public PaginationInfo getPaginationInfo() {
if(propertyService==null){
System.out.println("propertyService : " + "null");
}else
{
paginationInfo.setRecordCountPerPage(propertyService.getInt("pageUnit"));
paginationInfo.setPageSize(propertyService.getInt("pageSize"));
}
return paginationInfo;
}
}
이런식으로 VO 클래스에서 Injection 하게 설정을 했는데요.
막상 propertyService 를 사용 할려구 하면 NullPoint 가 납니다.
어떻게 해야 될까요.?
답변좀 부탁드립니다~!!
component-scan 에서는 base-package 로 지정이 되어 있습니다.
A
안녕하세요.. 김석환님..
아마도.. XXXVO를 new를 통해 직접 생성하신 경우 같습니다..
이 경우 IoC container에 의해 관리되는 XXXVO가 호출된 것이 아니라.. 그냥 POJO 객체가 생성되기 때문에.. DI가 적용되지 않습니다..
즉.. XXXVO도.. 다른 Bean(@Controller, @Service, @Repository)에 injection되어 사용하셔야 합니다...
다만.. Bean 자체가.. Singleton 방식이다보니.. VO를 bean으로 사용하시는 것은.. 문제가 발생할 수 있습니다. (전혀 엉뚱한 값이 들어갈 수 있음)
이 부분은 주의하셔야 합니다.
그럼.. 즐거운 하루되십시오.
감사합니다.
아마도.. XXXVO를 new를 통해 직접 생성하신 경우 같습니다..
이 경우 IoC container에 의해 관리되는 XXXVO가 호출된 것이 아니라.. 그냥 POJO 객체가 생성되기 때문에.. DI가 적용되지 않습니다..
즉.. XXXVO도.. 다른 Bean(@Controller, @Service, @Repository)에 injection되어 사용하셔야 합니다...
다만.. Bean 자체가.. Singleton 방식이다보니.. VO를 bean으로 사용하시는 것은.. 문제가 발생할 수 있습니다. (전혀 엉뚱한 값이 들어갈 수 있음)
이 부분은 주의하셔야 합니다.
그럼.. 즐거운 하루되십시오.
감사합니다.