이상한 피험자는 질문 자체를 계속 진행합니다. 스프링 응용 프로그램 컨텍스트에서 스프링 테스트 클래스에 접근 할 수있는 방법이 있습니까?스프링 컨텍스트에서 Spring 테스트 클래스 객체에 액세스
@Component
public class SimpleDaoHandler implements ApplicationContextAware, InitializingBean {
private ApplicationContext applicationContext;
private static Logger logger = Logger.getLogger(SimpleDaoHandler.class);
@Override
public void afterPropertiesSet() throws Exception {
//I have the application context now, via method "setApplicationContext"
// and need to get test class object to get the
// annotated field "TestAnnotation" because I also need to set this
// field with my business logic, using reflection.
// Problem is; test class object is not included in the
// "applicationContext" as a bean and I don't know how to access my
//test class which is already starting the spring context initialization.
//I need to get that test class object.
}
@Override
public void setApplicationContext(final ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
단서 :
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext-core.xml")
public class DbFuntionTests {
@TestAnnotation
private UserSessionDao userSessionDao;
@Test
public void testOracleTimestamp() throws Exception {
userSessionDao.findAll();
}
}
스프링 컨텍스트의 초기화 후 핸들러 클래스 : 질문 세부 사항은 주석 블록 :
테스트 클래스로 "SimpleDaoHandler"클래스에 숨겨져있다?
당신은 맞습니다. @Autowired와 AutowiredAnnotationBeanPostProcessor가이 작업을 수행 할 수있는 방법이 있지만 코드가 너무 복잡해서 코드가 너무 복잡해서 코드를 이해하기 어렵습니다. :)). 어떤 방법 으로든, 당신의 답은 다른 종류의 후 처리기를 시도하도록 이끌어줍니다. 어떤 결과라도 얻으면, 당신에게 알려줄 것입니다. 답장을 보내 주셔서 감사합니다. – MartK
그래, 복잡해 보이지만, 자동 완성 로직을 구현했기 때문에 - @Autowired annotation lookup 때문이 아니다.) - 사용자 정의 어노테이션으로 작업하는 간단한 포스트 프로세서의 예를 보여 주었다. –
당신의 대답은 더 자세합니다, 그래서 저는 제 대답을 선택했습니다 :) 시청자들은 아래의 답을 찾을 수 있습니다. – MartK