Junit - 通过注解加载Spring XML配置

4
我正在使用Camel 2.15.2,Spring 4.1.7.RELEASE,CXF 3.0.4和Junit 4.12进行开发。
当我运行以下测试时,加载Spring应用程序上下文失败:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(locations=
            {
                "classpath:com/me/someFile.xml",
                "classpath:META-INF/spring/someFile.xml"
            })
public class MyRouteTest extends CamelTestSupport
{
    //...
}

我收到的异常信息如下:

Caused by: java.lang.IllegalArgumentException: Cannot find RouteContext with id someRoute
    at org.apache.camel.model.RouteContextRefDefinitionHelper.lookupRoutes(RouteContextRefDefinitionHelper.java:65)

但是当我运行这个测试时,Spring 应用程序上下文成功加载:

public class MyRouteTest extends CamelSpringTestSupport
{
    @Override
    protected AbstractApplicationContext createApplicationContext()
    {
        return new ClassPathXmlApplicationContext(new String[]
                {
                    "classpath:com/me/someFile.xml",
                    "classpath:META-INF/spring/someFile.xml"
                });
    }

    //...
}

为什么第一种情况会失败?

这两种加载Spring应用程序上下文的方式不是等效的吗?


你尝试过在使用注解时不扩展CamelTestSupport吗? - Ralf
@Ralf 不,因为1. 我想在我的测试中使用许多它的酷方法 2. 如果这很重要,那么据我所知,这仍然不是预期的行为。 - rapt
1个回答

0

我认为答案与这个问题相同。AbstractApplicationContext versus ApplicationContext 没有看到您实际的上下文文件,很难确定更严格的ApplicationContext实现所需的@ContextConfiguration注释失败的确切原因。希望这可以帮助您!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接