我正在使用 设置和应用程序,我已经为静态文件Undertow
设置了一个,供apache-camel 用来公开其余服务。ResourceHandler
Servlet
我已经在应用容器中使用 spring 和 servlet3.0 完成了这项工作。
在一个类扩展org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
@Override
public void onStartup(ServletContext servletContext) throws ServletException
{
super.onStartup(servletContext);
ServletRegistration.Dynamic servlet = servletContext.addServlet("RestServlet", new CamelHttpTransportServlet());
servlet.setLoadOnStartup(1);
servlet.addMapping("/rest/*");
}
在骆驼路线
restConfiguration()
.component("RestServlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true");
非常接近http://camel.apache.org/servlet.html中描述的内容
但是,如果我在 Undertow 中作为嵌入式执行此操作,org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: RestServlet of type: org.apache.camel.spi.RestConsumerFactory
我猜 Guice 永远不会找到由 Undertow 创建的 servlet。我试图将 CamelHttpTransportServlet 手动公开为 Guice 绑定,但这似乎并没有改变。
ClassLoader classLoader = getClass().getClassLoader();
ResourceHandler staticHandler = new ResourceHandler(new ClassPathResourceManager(classLoader, STATIC_RESOURCE_ROOT))
.addWelcomeFiles(INDEX_HTML);
DeploymentInfo deploymentInfo = Servlets.deployment()
.setClassLoader(classLoader)
.setContextPath(ROOT_MAPPING)
.setDeploymentName(DEPLOYMENT_NAME)
.addServlet(
Servlets.servlet("RestServlet", CamelHttpTransportServlet.class)
.addMapping(REST_MAPPING)
.setLoadOnStartup(1)
);
DeploymentManager manager = Servlets.defaultContainer().addDeployment(deploymentInfo);
manager.deploy();
PathHandler path = Handlers.path()
.addPrefixPath(REST_MAPPING, manager.start())
.addPrefixPath(ROOT_MAPPING, staticHandler);
undertow = Undertow.builder()
.addHttpListener(port, LOCALHOST)
.setHandler(path)
.build();
undertow.start();
静态资源按预期工作,似乎其余 servlet 正在运行并获得响应但CamelContext
不会启动。
我不能在骆驼中使用restlet或任何东西,因为端口将被使用,所以我需要为静态文件和休息使用不同的端口。有没有办法让骆驼识别Servlet
发起者Undertow
?