简体   繁体   中英

Integration Grizzly2.2.X with Jersey and Spring

I have successfully integrated Grizzly v2.1.9 with Jersey and Spring . But could not make it work when trying to migrate Grizzly to version 2.2.19 .

The original code with Grizzly v2.1.9 is as below.

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();

And the new code with Grizzly v2.2.19 is as below

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();

The new code could be compiled and executed with no exception. However all urls which should be forwarded to different methods by Jersey are now all forwarded to the default page "/".

UPDATE

For someone who meets the same problem.

It is fixed after Grizzly2.2.20

Finally I get a workaround after sending an email to java.net.

Change

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

to

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

Can follow this link for more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM