Apache camel 使用ApacheCamel公开RESTAPI-获取404
我尝试了非常简单的方法:Apache camel 使用ApacheCamel公开RESTAPI-获取404,apache-camel,Apache Camel,我尝试了非常简单的方法: restConfiguration() .component("servlet"); rest().get("/hello") .to("direct:hello"); from("direct:hello") .log(LoggingLevel.INFO, "Hello World
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信息25248---[main]o.a.c.i.e.InternalRouteStartupManager:Route:route1从以下位置启动和使用:direct://hello
2021-04-14 15:03:31.760信息25248---[main]o.a.c.i.e.InternalRouteStartupManager:路由:路由2从:servlet开始和使用:/hello
2021-04-14 15:03:31.768信息25248---[main]o.a.c.impl.engine.AbstractCamelContext:总共2条路线,其中2条已启动
2021-04-14 15:03:31.768信息25248---[main]o.a.c.impl.engine.AbstractCamelContext:ApacheCamel 3.7.1(Camel-1)在220ms内启动
然而,当我试图到达这个地址,我得到404错误
{
“时间戳”:“2021-04-14T12:17:11.975+00:00”,
“状态”:404,
“错误”:“未找到”,
“电文”:“,
“路径”:“/你好”
}
在我的控制台中:
2021-04-14 15:17:11.973警告25248---[nio-8080-exec-4]o.s.web.servlet.PageNotFound:没有GET/hello的映射
你知道怎么解决吗?
我想在这里说,我在谷歌上搜索了这个问题和解决方案,就像使用“camel.component.servlet.mapping.context-path”一样=/*
或者使用“camel”前缀对我不起作用
谢谢 创建一个类似于任何配置类的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;
}}
例如骆驼座和弹簧靴: