java 集成grizzly_java – 与Jersey和Spring集成Grizzly2.2.X

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

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现在都转发到默认页面“/”.

UPDATE

对于遇到同样问题的人.

它在Grizzly2.2.20之后修复

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值