【问题标题】:Exposing Rest API with Apache Camel - getting 404使用 Apache Camel 公开 Rest API - 得到 404
【发布时间】:2021-04-14 12:21:44
【问题描述】:

我尝试了非常简单的路线:

    restConfiguration()
            .component("servlet");

    rest().get("/hello")
            .to("direct:hello");

    from("direct:hello")
            .log(LoggingLevel.INFO, "Hello World")
            .transform().simple("Hello World");

确实,在启动我的 Spring Boot 应用程序时,我可以看到路由在监听它: [在此处输入图片说明][1]

2021-04-14 15:03:31.759 INFO 25248 --- [main] o.a.c.i.e.InternalRouteStartupManager:路由:route1 开始并使用:direct://hello 2021-04-14 15:03:31.760 INFO 25248 --- [main] o.a.c.i.e.InternalRouteStartupManager:路由:route2 开始并使用:servlet:/hello 2021-04-14 15:03:31.768 INFO 25248 --- [main] o.a.c.impl.engine.AbstractCamelContext :共有 2 条路线,其中 2 条已启动 2021-04-14 15:03:31.768 INFO 25248 --- [main] o.a.c.impl.engine.AbstractCamelContext:Apache Camel 3.7.1 (camel-1) 在 220 毫秒内启动

但是,当我尝试到达此地址时,我收到 404 错误。

{ "时间戳": "2021-04-14T12:17:11.975+00:00", “状态”:404, “错误”:“未找到”, “信息”: ””, “路径”:“/你好” }

在我的控制台中: 2021-04-14 15:17:11.973 WARN 25248 --- [nio-8080-exec-4] os.web.servlet.PageNotFound : 没有 GET /hello 的映射

知道如何解决吗? 我会在这里说,我用谷歌搜索了这个问题和解决方案,比如使用“camel.component.servlet.mapping.context-path=/* " 或使用 "camel" 前缀对我不起作用。

谢谢!

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    创建一个像任何配置类一样的bean

      @SpringBootApplication
        public class DemoApplication {
            public static void main(String[] args) {
                SpringApplication.run(DemoApplication.class, args);
            }
        
            @Bean
            public ServletRegistrationBean camelServletRegistrationBean() {
                ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), "/*");
                registration.setName("CamelServlet");
                return registration;
            }}
    

    例如骆驼休息和弹簧靴:https://github.com/erayerdem/camelrest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 2023-03-10
      • 2021-01-21
      • 2014-07-20
      • 2020-10-02
      相关资源
      最近更新 更多