2013-01-14 28 views
5

Tôi đã tích hợp thành công Grizzly v2.1.9 với JerseySpring. Nhưng không thể làm cho nó hoạt động khi cố gắng di chuyển Grizzly sang phiên bản 2.2.19.Tích hợp Grizzly2.2.X với Jersey và Spring

Mã gốc với Grizzly v2.1.9 như sau.

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

Và mã mới với Grizzly v2.2.19 như sau

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

Mã mới có thể được biên dịch và thực thi không có ngoại lệ. Tuy nhiên, tất cả các url cần được chuyển tiếp đến các phương thức khác nhau bởi Jersey hiện được chuyển tiếp đến trang mặc định "/".

CẬP NHẬT

Đối với những người gặp vấn đề tương tự.

Được sửa sau Grizzly2.2.20

Trả lời

3

Cuối cùng, tôi nhận được giải pháp sau khi gửi email đến java.net.

Thay đổi

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

để

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

có thể làm theo này link để xem chi tiết hơn.

Các vấn đề liên quan