[英]ApplicationContext loads when JUnit test run from eclipse, but not from ant build
Seems weird to me. 对我来说似乎很奇怪。 JUnit test runs fine from eclipse.
从Eclipse开始,JUnit测试运行良好。 But when I run from Ant command line, it shows error.
但是,当我从Ant命令行运行时,它显示错误。 Looks like its not loading / application context.
看起来它没有加载/应用程序上下文。 Here is the base class of test class.
这是测试类的基类。
@ContextConfiguration(locations = { "classpath*:applicationContext.xml"})
public abstract class TransactionalTestCase extends StrutsSpringTransactionalTests {
@Before
public void onSetUp() throws Exception {
super.setUp();
}
@Override
protected void setupBeforeInitDispatcher() throws Exception {
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);
}
When I try to print appContext
in this method, it prints org.springframework.context.support.GenericApplicationContext@9320aa71: startup date xxxxxxx 当我尝试使用此方法打印
appContext
时,它将打印org.springframework.context.support.GenericApplicationContext@9320aa71:启动日期xxxxxxx
But it prints null from ant build command line. 但是它从ant build命令行输出null。
I compared the classpath of both eclipse and ant. 我比较了eclipse和ant的类路径。 Both are same.
两者都一样。 Includes same set of files and folders.
包括相同的文件和文件夹集。
@ContextConfiguration
not taking effect when I run from ant build? 当我从ant build运行时,
@ContextConfiguration
无法生效吗?
What else could be wrong? 还有什么可能是错的?
StrutsSrpingTransactionalTests class StrutsSrpingTransactionalTests类
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
TransactionalTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class
})
@Transactional
public abstract class StrutsSpringTransactionalTests extends StrutsTestCase implements ApplicationContextAware {
protected ApplicationContext appContext;
@Override
public void setApplicationContext(ApplicationContext appContext) throws BeansException {
this.appContext = appContext;
}
}
Figured it out that, the problem is with JUnit versions. 弄清楚,问题出在JUnit版本上。 Eclipse used Junit4, while ant used Junit3 by default.
Eclipse默认使用Junit4,而ant默认使用Junit3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.