Java 一次运行的SpringCamel应用程序

Java 一次运行的SpringCamel应用程序,java,spring,apache-camel,Java,Spring,Apache Camel,我正在尝试创建一个应用程序,它将只在特定情况下使用,不时 情况如下 用户运行应用程序 应用程序从spring-context.xml camel-context.xml开始 创建AppRoute.java中的路由 执行使用创建的路由的方法 结束 然而,我有一个问题,因为每当我使用main.run()时,我可以看到创建了route,但方法没有执行。不使用main.run()方法,但不生成route 我的主要意见是: import org.apache.camel.spring.Main; impo

我正在尝试创建一个应用程序,它将只在特定情况下使用,不时

情况如下

  • 用户运行应用程序
  • 应用程序从spring-context.xml camel-context.xml开始
  • 创建AppRoute.java中的路由
  • 执行使用创建的路由的方法
  • 结束
  • 然而,我有一个问题,因为每当我使用
    main.run()
    时,我可以看到创建了
    route
    ,但方法没有执行。不使用
    main.run()
    方法,但不生成
    route

    我的主要意见是:

    import org.apache.camel.spring.Main;
    import org.springframework.stereotype.Component;
    
    
    public class EgzekutorManual extends Main{
        @Produce(uri="direct:tester")
        static ProducerTemplate pt;
        public static void main(String[] args) throws Exception {
            Main main = new Main();
            main.showOptions();
            main.run();
            main.addRouteBuilder(new AppRoute());
            manualTester();
        }
        public void manualTester(){
            System.out.println("Manual tester executed");
            pt.sendBody("X");
        }
    }
    
    AppRoute.java:

    private static class AppRoute extends RouteBuilder {
            @Override
            public void configure() throws Exception {
                from("direct:tester")
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            System.out.println("Tester received message");
                        }
                    });
            }
        }
    

    有人能告诉我我做错了什么吗?

    您必须以某种方式调用direct:tester路由(例如,从另一个路由或从生产者),这与路由的调用无关。在此示例中,将永远不会调用
    manualTester
    方法。main.run()等待进程完成,但它不会发生。只需将main.run()作为main方法的最后一行
    nullpointerexception
    创建路由,并在最后设置
    main.run()
    (在ProducerTemplate.sendbody方法时使用nullpointer)@ConMan您可以在这里找到有关.run()方法的更多信息您必须以某种方式调用direct:tester路由(例如,从另一个路由或生产商)这与路由的调用无关。在本例中,
    manualTester
    方法将永远不会被调用。请参阅。main.run()等待进程完成,但它不会发生。只需移动main.run()作为main方法
    nullpointerexception
    的最后一行,没有在最后设置
    main.run()
    的情况下创建路由(nullpointer而ProducerTemplate.sendbody方法)@ConMan您可以在这里找到关于.run()方法的更多信息