奇怪的主题继续问题本身:) 有没有办法从弹簧应用程序上下文中到达弹簧测试类?问题详细信息作为注释块隐藏在“SimpleDaoHandler”类中:)
测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext-core.xml")
public class DbFuntionTests {
@TestAnnotation
private UserSessionDao userSessionDao;
@Test
public void testOracleTimestamp() throws Exception {
userSessionDao.findAll();
}
}
spring上下文初始化后的一个handler类:
@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;
}
有什么线索吗?