简体   繁体   English

在测试Spring Boot Camel应用程序时出现NullPointerException

[英]NullPointerException while testing Spring boot camel application

public class MyRouteTest extends CamelSpringTestSupport {

    @Override
    protected AbstractApplicationContext createApplicationContext() {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.scan("com.mypackage.routes");
        ctx.refresh();
        return ctx;
    }
    @Test
    public void testRouteRunning() throws Exception {
       assertTrue(context().getRouteStatus("direct:start").isStarted());
    }
}

getRouteStatus is returning null I am following this to write my test cases getRouteStatus返回null我正在按照编写测试用例

Any pointers on how to fix this will be very helpful. 关于如何解决此问题的任何指示都将非常有帮助。

You need to use the id of the route, not the url, eg "direct:start" is the url of the route, the route has an id as well. 您需要使用路由的ID,而不是URL,例如,“ direct:start”是路由的URL,路由也具有ID。 If you do not specify an id, then an id is auto assigned such as route1 , route2 etc. 如果不指定ID,然后一个id是自动分配,如route1route2等。

Use .routeId("myNameHere") to specify the id of a route. 使用.routeId("myNameHere")指定路由的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM