Spring boot 带Camel 2.25的Spring boot 2.x:特定于Spring的端点不工作
我有一个springboot2.x和camel2.25的项目。它有不同的骆驼路线,很少有休息消费者路线。到目前为止一切都很好 现在,我添加了几个带有一些端点的普通spring boot@RestController类。但这些都不起作用(抛出404) 当我调查时,我发现,每个请求都会到达CamelServlet,它完全不知道基于spring的普通@RestController端点(但只知道Camel-REST消费者路由端点)。因此,仅对@RestController端点抛出此错误,而Camel REST端点仍在工作 下面是我的配置Spring boot 带Camel 2.25的Spring boot 2.x:特定于Spring的端点不工作,spring-boot,apache-camel,camel-rest,Spring Boot,Apache Camel,Camel Rest,我有一个springboot2.x和camel2.25的项目。它有不同的骆驼路线,很少有休息消费者路线。到目前为止一切都很好 现在,我添加了几个带有一些端点的普通spring boot@RestController类。但这些都不起作用(抛出404) 当我调查时,我发现,每个请求都会到达CamelServlet,它完全不知道基于spring的普通@RestController端点(但只知道Camel-REST消费者路由端点)。因此,仅对@RestController端点抛出此错误,而Camel R
spring:
application:
name: gateway
main:
web-application-type: SERVLET
server:
servlet:
context-path: /gateway
port: 8080
camel:
springboot:
name: gateway
component:
servlet:
mapping:
enabled: true
context-path: /*
mail:
basic-property-binding: true
下面是我的POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet-starter</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mail-starter</artifactId>
</dependency>
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动启动器验证
org.apache.camel
驼形弹簧靴起动器
org.apache.camel
骆驼起动器
运行时
org.apache.camel
骆驼邮递起动器
我做错什么了吗?有什么建议吗?提前感谢。这是因为您设置了上下文路径:/*模式意味着camel将在spring servlet dispatcher处理它之前拦截它(因为该路径是向camel注册的),所以如果您想处理@Restcontroller,那么您需要为camel定义一个单独的上下文路径,示例:上下文路径:camel api/*模式,现在camel将注册camel api基本路由,如果模式与camel apiURL不同,它将通过spring引导处理
@Bean
ServletRegistrationBean servletRegistrationBean() {
ServletRegistrationBean servlet = new ServletRegistrationBean
(new CamelHttpTransportServlet(), "camel-api/*");
servlet.setName("CamelServlet");
return servlet;
}
或者使用属性进行配置。谢谢您的回答,这非常有帮助。但是,我们真的有办法使用配置属性来配置这两个不同的url(比如驼峰api/*和其他url)吗?我这样问的原因是,在Spring boot 2.x环境中,我没有明确配置任何Servlet bean。
camel:springboot:name:gateway component:Servlet:mapping:enabled:true context path:camel api/*
您可以在这里根据路径格式模式设置路径,另外,该模式将自动注册引导rest控制器。可以配置多个相对路径以向camel新ServletRegistrationBean(CamelHttpTransportServlet(),“camel api/*”,“anotherpattern/*”)注册代码>我不确定如何使用属性实现它,因为我没有找到属性自动配置cls,您可以找到cls并找出它的属性类型。另外,我的建议是,如果您已经在使用camel API组件,请继续使用它,不是也集成@RestController。感谢您的澄清,Bhushan的回答在这种情况下是合适的,但为了结束对话,我想指出另一个选项,将驼峰路线与非驼峰应用程序集成,正如@Clause Ibsen在博客中提到的(我失去了链接)。对于任何非camel应用程序,我们可以使用camel中的FluentProducerTemplate,它可以在Spring Rest控制器类中的任意位置使用EndpointInject注释自动连接,并可以用于将camel交换发送到任何camel端点。