RestBindingMode.auto 出现 Camel 错误
Posted
技术标签:
【中文标题】RestBindingMode.auto 出现 Camel 错误【英文标题】:Getting Camel error with RestBindingMode.auto 【发布时间】:2020-12-21 11:09:18 【问题描述】:在下一行.bindingMode(RestBindingMode.auto)
使用 maven 运行 springboot Camel 时出现错误。
cannot find symbol
symbol: variable RestBindingMode
location: class com.example.MySpringBootRouter
我是否缺少一些依赖项?
我认为这应该不是问题,因为我的 pom.xml
中有下一个依赖项,但我不知道为什么会出现此错误。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-camel-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>A Camel Spring Boot Route</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.boot-version>2.3.0.RELEASE</spring.boot-version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>$spring.boot-version</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>3.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-stream-starter</artifactId>
</dependency>
<!-- JMS -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jms-starter</artifactId>
</dependency>
<!-- REST -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-rest-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-servlet-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jackson-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jaxb-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-netty-http-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jetty-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>$spring.boot-version</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
MySpringBootRouter.java
package com.example;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
/**
* A simple Camel route that triggers from a timer and calls a bean and prints to system out.
* <p/>
* Use <tt>@Component</tt> to make Camel auto detect this route when starting.
*/
@Component
public class MySpringBootRouter extends RouteBuilder
@Override
public void configure()
String listenAddress = "192.168.0.50";
int listenPort = 8161;
restConfiguration()
.component("servlet")
//.component("jetty")
//.component("netty-http")
.scheme("http")
.host(listenAddress)
.bindingMode(RestBindingMode.auto)
.dataFormatProperty("prettyPrint", "true")
.port(listenPort);
rest("/artemis-rest/queues/test")
.post()
.produces("application/json")
.to("direct:route1");
from("direct:route1")
.convertBodyTo(String.class)
.log("Boo!");
如果我评论//.bindingMode(RestBindingMode.auto)
骆驼启动OK。
【问题讨论】:
看你发的类,你缺的是import org.apache.camel.model.rest.RestBindingMode 谢谢。这解决了.bindingMode(RestBindingMode.auto)
的问题。
【参考方案1】:
正如卢卡所说,我忘记在 MySpringBootRouter.java 中导入 RestBindingMode。
import org.apache.camel.model.rest.RestBindingMode
【讨论】:
以上是关于RestBindingMode.auto 出现 Camel 错误的主要内容,如果未能解决你的问题,请参考以下文章