【问题标题】:Integration Grizzly2.2.X with Jersey and Spring将 Grizzly2.2.X 与 Jersey 和 Spring 集成
【发布时间】:2013-01-14 12:32:16
【问题描述】:

我已经成功地将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();

新代码可以毫无例外地编译和执行。但是,所有应该由Jersey 转发到不同方法的 url 现在都转发到默认页面“/”。

更新

对于遇到同样问题的人。

Grizzly2.2.20之后修复

【问题讨论】:

    标签: java spring web jersey grizzly


    【解决方案1】:

    在向 java.net 发送电子邮件后,我终于得到了解决方法。

    改变

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

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

    可以关注link了解更多详情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      相关资源
      最近更新 更多