我已经成功地将Grizzly v2.1.9JerseySpring集成在一起。但是在尝试将Grizzly迁移到2.2.19版本时无法正常工作。

带有Grizzly v2.1.9的原始代码如下。

HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2", "localhost", 3388);
server.addListener(listener);

ServletHandler sa = new ServletHandler();
sa.setContextPath("/");
sa.setServletInstance(new SpringServlet());
sa.addContextParameter("contextConfigLocation", "classpath:spring-context.xml");
sa.addServletListener("org.springframework.web.context.ContextLoaderListener");
sa.addServletListener("org.springframework.web.context.request.RequestContextListener");

ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(sa, new String[] {"/"});
server.start();

并且带有Grizzly v2.2.19的新代码如下
HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2", "localhost", 3388);
WebappContext ctx = new WebappContext("ctx","/");
final ServletRegistration reg = ctx.addServlet("spring", new SpringServlet());
reg.addMapping("/*");
ctx.addContextInitParameter("contextConfigLocation", "classpath:spring-context.xml");
ctx.addListener("org.springframework.web.context.ContextLoaderListener");
ctx.addListener("org.springframework.web.context.request.RequestContextListener");
ctx.deploy(server);
server.start();

可以毫无异常(exception)地编译和执行新代码。但是,应该通过Jersey转发到不同方法的所有URL现在都转发到默认页面“/”。

更新

对于遇到相同问题的人。

在Grizzly2.2.20之后修复

最佳答案

最终,在将电子邮件发送到java.net之后,我得到了一种解决方法。

改变

WebappContext ctx = new WebappContext("ctx","/");


WebappContext ctx = new WebappContext("ctx","");

可以关注此link以获得更多详细信息。

10-08 09:12
查看更多