Java 驼峰cxf带弹簧引导手动启动路线
我使用最新版本的SpringBoot和camel cxf来公开rest/SOAPWeb服务。但是,由于我有许多服务,并且其中一些服务没有很好地定义,所以我希望逐个注册它们,捕获是否发生任何异常,并继续使用剩余的有效服务。但当我设置camel.springboot.auto startup=false时,我无法再次打开cxf服务。(请注意,计时器路径可以通过这种方式启动)。有什么解决办法或建议吗Java 驼峰cxf带弹簧引导手动启动路线,java,spring-boot,apache-camel,cxf,Java,Spring Boot,Apache Camel,Cxf,我使用最新版本的SpringBoot和camel cxf来公开rest/SOAPWeb服务。但是,由于我有许多服务,并且其中一些服务没有很好地定义,所以我希望逐个注册它们,捕获是否发生任何异常,并继续使用剩余的有效服务。但当我设置camel.springboot.auto startup=false时,我无法再次打开cxf服务。(请注意,计时器路径可以通过这种方式启动)。有什么解决办法或建议吗 @Component public class TestRoutes { @Autowire
@Component
public class TestRoutes {
@Autowired CamelContext camelContext;
@Autowired Swagger2Feature swagger2Feature;
@PostConstruct
public void init(){
try {
camelContext.start();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
HelloResponse response = new HelloResponse();
response.setCevap("response");
List<Object> providers = new ArrayList<>();
CxfRsComponent cxfComponent = new CxfRsComponent(camelContext);
CxfRsEndpoint serviceEndpoint = new CxfRsEndpoint("/rest2", cxfComponent);
serviceEndpoint.addResourceClass(Service1.class);
serviceEndpoint.setProviders(providers);
serviceEndpoint.setSynchronous(true);
serviceEndpoint.setAddress("/rest2");
serviceEndpoint.getFeatures().add(swagger2Feature);
RouteBuilder builder = new RouteBuilder(camelContext) {
@Override
public void configure() throws Exception {
from(serviceEndpoint)
.id(Service1.class.getCanonicalName()+"rest")
.log("${header.operationName} message here")
.setBody(constant(response));
from("timer:mytimer?period=5000")
.id("timer")
.log("hi");
}
};
try {
camelContext.startRoute(Service1.class.getCanonicalName()+"rest");
camelContext.startRoute("timer");
} catch (Exception e) {
e.printStackTrace();
}
}
}
2017-07-18 10:50:49.076 INFO 12052 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5149d738: startup date [Tue Jul 18 10:50:49 EEST 2017]; root of context hierarchy
2017-07-18 10:50:52.413 INFO 12052 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$5d14135] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-18 10:50:53.063 INFO 12052 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-18 10:50:53.085 INFO 12052 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-07-18 10:50:53.086 INFO 12052 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache
Tomcat/8.5.11
2017-07-18 10:50:53.341 INFO 12052 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-07-18 10:50:53.342 INFO 12052 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4269 ms
2017-07-18 10:50:53.974 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-07-18 10:50:53.976 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'CXFServlet' to [/services/*]
2017-07-18 10:50:53.981 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-18 10:50:53.982 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-07-18 10:50:53.982 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-07-18 10:50:53.982 INFO 12052 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-07-18 10:50:54.682 INFO 12052 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.19.1 (CamelContext: camel-1) is starting
2017-07-18 10:50:54.685 INFO 12052 --- [ main] o.a.c.m.ManagedManagementStrategy : JMX is enabled
2017-07-18 10:50:54.999 INFO 12052 --- [ main] o.a.c.i.converter.DefaultTypeConverter : Loaded 214 type converters
2017-07-18 10:50:55.064 INFO 12052 --- [ main] o.a.c.i.DefaultRuntimeEndpointRegistry : Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
2017-07-18 10:50:55.094 INFO 12052 --- [ main] o.a.camel.spring.SpringCamelContext : 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
2017-07-18 10:50:55.095 INFO 12052 --- [ main] o.a.camel.spring.SpringCamelContext : Total 0 routes, of which 0 are started.
2017-07-18 10:50:55.097 INFO 12052 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.19.1 (CamelContext: camel-1) started in 0.415 seconds
2017-07-18 10:50:55.301 WARN 12052 --- [ main] o.apache.cxf.jaxrs.utils.ResourceUtils : No resource methods have been found for resource class java.lang.Class
2017-07-18 10:50:55.433 INFO 12052 --- [ main] org.apache.cxf.endpoint.ServerImpl : Setting the server's publish address to be /rest1
2017-07-18 10:50:55.636 INFO 12052 --- [ main] org.reflections.Reflections : Reflections took 60 ms to scan 1 urls, producing 21 keys and 25 values
2017-07-18 10:50:56.106 INFO 12052 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5149d738: startup date [Tue Jul 18 10:50:49 EEST 2017]; root of context hierarchy
2017-07-18 10:50:56.206 INFO 12052 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-07-18 10:50:56.208 INFO 12052 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-07-18 10:50:56.267 INFO 12052 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-18 10:50:56.267 INFO 12052 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-18 10:50:56.330 INFO 12052 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-18 10:50:57.591 INFO 12052 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-07-18 10:50:57.686 INFO 12052 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-07-18 10:50:57.694 INFO 12052 --- [ main] c.e.demo.AutoStartupFalseApplication : Started AutoStartupFalseApplication in 9.057 seconds (JVM running for 9.764)
@组件
公共类测试路由{
@自动连接的CamelContext和CamelContext;
@自动连线的Swigger2功能Swigger2功能;
@施工后
公共void init(){
试一试{
camelContext.start();
}捕获(异常e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
HelloResponse response=新HelloResponse();
响应。setCevap(“响应”);
列表提供程序=新的ArrayList();
CxfRsComponent cxfComponent=新的CxfRsComponent(上下文);
CxfRsEndpoint serviceEndpoint=新的CxfRsEndpoint(“/rest2”,cxfComponent);
serviceEndpoint.addResourceClass(Service1.class);
setProviders(提供者);
serviceEndpoint.setSynchronous(true);
serviceEndpoint.setAddress(“/rest2”);
serviceEndpoint.getFeatures().add(swagger2Feature);
RouteBuilder builder=新RouteBuilder(camelContext){
@凌驾
public void configure()引发异常{
来自(serviceEndpoint)
.id(Service1.class.getCanonicalName()+“rest”)
.log(“此处为${header.operationName}消息”)
.setBody(常数(响应));
从(“计时器:mytimer?周期=5000”)
.id(“计时器”)
.log(“hi”);
}
};
试一试{
camelContext.startRoute(Service1.class.getCanonicalName()+“rest”);
camelContext.startRoute(“计时器”);
}捕获(例外e){
e、 printStackTrace();
}
}
}
2017-07-18 10:50:49.076信息12052---[main]国家配置嵌入式Web应用程序上下文:刷新org.springframework.boot.context.embedded。AnnotationConfigEmbeddedWebApplicationContext@5149d738:启动日期[2017年7月18日星期二10:50:49];上下文层次结构的根
2017-07-18 10:50:52.413信息12052---[main]trationlegate$BeanPostProcessorChecker:Bean'org.apache.camel.spring.boot.CamelAutoConfiguration'类型为[org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$5d14135]的Bean'org.apache.camel(例如:不符合自动代理的条件)
2017-07-18 10:50:53.063信息12052---[main]s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat已用端口初始化:8080(http)
2017-07-18 10:50:53.085信息12052---[main]o.apache.catalina.core.StandardService:启动服务Tomcat
2017-07-18 10:50:53.086信息12052---[main]org.apache.catalina.core.StandardEngine:启动Servlet引擎:apache
Tomcat/8.5.11
2017-07-18 10:50:53.341信息12052---[ost-startStop-1]o.a.c.c.c.[Tomcat].[localhost].[/]:初始化Spring嵌入式WebApplicationContext
2017-07-18 10:50:53.342信息12052---[ost-startStop-1]o.s.web.context.ContextLoader:根WebApplicationContext:初始化在4269毫秒内完成
2017-07-18 10:50:53.974信息12052---[ost-startStop-1]o.s.b.w.servlet.ServletRegistrationBean:将servlet:“dispatcherServlet”映射到[/]
2017-07-18 10:50:53.976信息12052---[ost-startStop-1]o.s.b.w.servlet.ServletRegistrationBean:将servlet:“CXFServlet”映射到[/services/*]
2017-07-18 10:50:53.981信息12052---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“characterEncodingFilter”映射到:[/*]
2017-07-18 10:50:53.982信息12052---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“hiddenHttpMethodFilter”映射到:[/*]
2017-07-18 10:50:53.982信息12052---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“httpPutFormContentFilter”映射到:[/*]
2017-07-18 10:50:53.982信息12052---[ost-startStop-1]o.s.b.w.servlet.FilterRegistrationBean:将筛选器:“requestContextFilter”映射到:[/*]
2017-07-18 10:50:54.682信息12052---[main]o.a.camel.spring.SpringCamelContext:apachecamel 2.19.1(CamelContext:camel-1)正在启动
2017-07-18 10:50:54.685信息12052---[main]o.a.c.m.ManagedManagement策略:JMX已启用
2017-07-18 10:50:54.999信息12052---[main]o.a.c.i.converter.DefaultTypeConverter:Loaded 214类型转换器
2017-07-18 10:50:55.064信息12052---[main]o.a.c.i.DefaultRuntimeEndpointRegistry:运行时端点注册表处于扩展模式,正在收集所有传入和传出端点的使用统计信息(缓存限制:1000)
2017-07-18 10:50:55.094信息12052---[main]o.a.camel.spring.SpringCamelContext:未使用流缓存。如果使用流,则建议启用流缓存。有关更多详细信息,请参阅http://camel.apache.org/stream-caching.html
2017-07-18 10:50:55.095信息12052---[main]o.a.camel.spring.SpringCamelContext:总共有0条路线,其中0条已经启动。
2017-07-18 10:50:55.097信息12052---[main]o.a.camel.spring.SpringCamelContext:apachecamel 2.19.1(CamelContext:camel-1)在0.415秒内启动
2017-07-18 10:50:55.301警告12052---[main]o.apache.cxf.jaxrs.utils.ResourceUtils:未找到资源类java.lang.class的资源方法
2017-07-18 10:50:55.433信息12052---[main]org.apache.cxf.endpoint.ServerImpl:设置服务器的发布地址
@Bean(destroyMethod = "shutdown")
public SpringBus cxf() {
return new SpringBus();
}
@Autowired Bus bus;
.
.
CxfRsEndpoint serviceEndpoint = new CxfRsEndpoint("/rest2", cxfComponent);
.
.
serviceEndpoint.setBus(bus);