Java – integration with Jersey and spring grizzly2 2.X

I have successfully added grizzly v2 1.9 integrated with Jersey and spring But I'm trying to migrate grizzly to version 2.2 It will not work at 19 o'clock

Grizzly v2. The original code of 1.9 is as follows

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. The new code for 2.19 is shown below

HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2",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();

New code can be compiled and executed without exception However, all URLs that should be forwarded by Jersey to different methods are now forwarded to the default page "/

UPDATE

For people who encounter the same problem

It's in grizzly2 Repair after 2.20

Solution

Finally, I'm talking to Java Net after sending e - mail

change

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

to

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

You can follow this link for more details

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>