Wil*_*lly 5 java spring jersey grizzly web
我已经成功地Grizzly v2.1.9使用Jersey和Spring.但是在尝试迁移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();
Run Code Online (Sandbox Code Playgroud)
新代码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();
Run Code Online (Sandbox Code Playgroud)
新代码可以毫无例外地编译和执行.但是,应该转发到不同方法的所有URL Jersey现在都转发到默认页面"/".
UPDATE
对于遇到同样问题的人.
它在Grizzly2.2.20之后修复
最后,我在向 java.net 发送电子邮件后得到了解决方法。
改变
WebappContext ctx = new WebappContext("ctx","/");
Run Code Online (Sandbox Code Playgroud)
到
WebappContext ctx = new WebappContext("ctx","");
Run Code Online (Sandbox Code Playgroud)
可以点击此链接了解更多详细信息。
| 归档时间: |
|
| 查看次数: |
1721 次 |
| 最近记录: |