我正在使用Apache骆驼构建Spring Boot应用程序。我希望骆驼中的rest()
DSL在启动Spring Boot时侦听相同的端口。
我尝试遵循此link,但如果不使用servlet
组件就无法解决。我不想我的路线看起来像servlet:/hello
,而是想直接使用码头(jetty:http://0.0.0.0:0/hello)
我能够正确启动服务器,但是路由却没有发生。
调用http://localhost:8080/hello
无效。
日志
Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration] is not eligible for getting processed by all BeanPos
Logging initialized @1690ms to org.eclipse.jetty.util.log.Slf4jLog
Server initialized with port: 8080
jetty-9.4.27.v20200227; built: 2020-02-27T18:37:21.340Z; git: a304fd9f351f337e7c0e2a7c28878dd536149c6c; jvm 1.8.0_221-b11
Initializing Spring embedded WebApplicationContext
Root WebApplicationContext: initialization completed in 733 ms
DefaultSessionIdManager workerName=node0
No SessionScavenger set, using defaults
node0 Scavenging every 660000ms
Started @1882ms
Initializing ExecutorService 'applicationTaskExecutor'
Detected and using LURCacheFactory: camel-caffeine-lrucache
LiveReload server is running on port 35729
Loading additional Camel XML routes from: classpath:camel/*.xml
Loading additional Camel XML rests from: classpath:camel-rest/*.xml
JMX is enabled
Apache Camel 3.2.0 (CamelContext: ServicesRest) is starting
StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
Route: route1 started and consuming from: direct://getCustomer
jetty-9.4.27.v20200227; built: 2020-02-27T18:37:21.340Z; git: a304fd9f351f337e7c0e2a7c28878dd536149c6c; jvm 1.8.0_221-b11
Started o.e.j.s.ServletContextHandler@79c2e942{/,null,AVAILABLE}
Started ServerConnector@11d5056{HTTP/1.1, (http/1.1)}{0.0.0.0:63660}
Started @2441ms
Route: route2 started and consuming from: jetty:http://0.0.0.0:0/hello
Total 2 routes, of which 2 are started
Apache Camel 3.2.0 (CamelContext: ServicesRest) started in 0.043 seconds
Initializing Spring DispatcherServlet 'dispatcherServlet'
Initializing Servlet 'dispatcherServlet'
Completed initialization in 3 ms
Started ServerConnector@436343c0{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
Jetty started on port(s) 8080 (http/1.1) with context path '/'
Started CamelMicroservicesApplication in 1.688 seconds (JVM running for 2.462)
路线生成器
@Component
public class SimpleRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
rest("/").get("hello")
.produces("text/plain")
.to("direct:getCustomer")
.outType(String.class);
from("direct:getCustomer")
.log(LoggingLevel.INFO, "${body}");
}
}
build.gradle
dependencies {
implementation ('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
}
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation 'org.apache.camel.springboot:camel-spring-boot-starter:3.2.0'
implementation 'org.apache.camel.springboot:camel-rest-starter:3.2.0'
implementation 'org.apache.camel:camel-jetty:3.2.0'
}
}
答案 0 :(得分:0)
如果您将Spring Boot设置为使用任何HTTP服务器(tomcat,jetty,undertow),并且希望将其用作Camel Rest DSL的一部分,则应该使用camel-servlet-starter来使用servlet与Spring Boot集成。 HTTP服务器。