2013-03-25 4 views
1

위켓 응용 프로그램에 대한 테스트를 작성 중이며이를 수행하기 위해 페이지에 스프링 빈을 주입해야합니다 (주석으로 완료). 다음 코드를 고려하십시오 : 이것은 실제로 (더 nullpointer)를 작동하지 않을 것스프링 - 개찰구 : 리소스가있는 콩 주입

protected void setUp() { 
    tester = new WicketTester(); 
    scanService = new ScanService(); 

    ApplicationContextMock appctx=new ApplicationContextMock(); 
    appctx.putBean("pxGenericService", new PxGenericServiceImpl()); 

    tester.getApplication().getComponentInstantiationListeners().add(new SpringComponentInjector(tester.getApplication(), appctx)); 
} 

. 문제는 bean이 리소스 (@Resource annotation 변수)를 얻었고 페이지에서 테스트를 실행할 때이 리소스가 null (nullpointer 예외)로 판명되었다는 것입니다. 이 문제를 어떻게 수정합니까?

답변

0

또한 bean이 가지고있는 모든 종속성의 인스턴스를 모의 응용 프로그램 컨텍스트에 추가해야합니다. 따라서 PxGenericServiceImpl 클래스의 인스턴스를 appctx에 사용하십시오.

0

SpringComponentInjector@Resource을 지원하지 않는다고 생각합니다. 지원되는 유일한 주석은 @SpringBean@Inject입니다. AnnotProxyFieldValueFactory :

@Override 
public boolean supportsField(final Field field) 
{ 
    return field.isAnnotationPresent(SpringBean.class) || field.isAnnotationPresent(Inject.class); 
}