无法通过Ant在JUnit测试中自动装配 - 看起来像@RunWith(SpringJUnit4ClassRunner.class)不起作用

时间:2011-04-12 23:48:59

标签: java spring ant junit autowired

我的测试用例看起来像这样:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class AbstractDatabaseTestCase extends AbstractTestCase {

    @Autowired
    private SessionFactory sessionFactory;

}

出于某种原因,当我在我的计算机上本地运行它时,无论是通过Eclipse(使用Junit4测试运行器)还是使用ant(在eclipse中,或者只是在终端中),一切正常,sessionFactory被正确注入。

当此代码在服务器(Hudson)上时,要么通过Hudson运行它,要么通过执行ant测试(测试是构建和运行junit测试的目标)在控制台中运行它,sessionFactory不会被注入,它看起来像自动装配不起作用。我查看了nullpointerexception中的堆栈跟踪并注意到它没有使用SpringJUnit4ClassRunner,即使我在@RunWith注释中使用它(在我的本地计算机上它确实使用它)。有什么想法吗?我想这不是自动装配,因为它不使用SpringJUnit4ClassRunner。

由于

0 个答案:

没有答案
相关问题