吉斯+ Jersey:添加所有资源和提供程序,而不绑定到 Jersey Servlet
我目前正在使用 Jersey 1.8 结合 Guice 3.0 为我的 JPA 进行 DI 开发一个球衣应用程序。这很好地解决了我无法克服的一个主要问题:
我必须使用绑定手动将所有 Jersey 资源类添加到 JerseyServletModule:
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
install(new JpaPersistModule("DBName"));
filter("/*").through(PersistFilter.class);
/* bind the REST resources and serve*/
bind(Hello.class);
serve("/*").with(GuiceContainer.class);
}
});
}
我希望能够省略对每个资源和提供程序使用绑定并在 jersey-guice 文档中发现一条评论:http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
它基本上表明可以将球衣资源的注册传递给球衣 servlet。但是,我无法使用上述方法来管理此操作:
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
bind(GuiceResource.class);
Map<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
serve("/*").with(GuiceContainer.class, params);
}
}
});
遗憾的是,我无法获得有关球衣资源注册过程的更多信息。
任何帮助将不胜感激。当然,如果需要的话我可以提供更多信息! 谢谢。
Im currently working on an jersey application using Jersey 1.8 in conjunction with Guice 3.0 for DI for my JPA. This works pretty well with one major issue which I wasn't able to overcome:
I have to manually add all Jersey Resource classes to the JerseyServletModule using bind:
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
install(new JpaPersistModule("DBName"));
filter("/*").through(PersistFilter.class);
/* bind the REST resources and serve*/
bind(Hello.class);
serve("/*").with(GuiceContainer.class);
}
});
}
I would like to be able to ommit the use of bind for every single resource and provider and found in the jersey-guice doc a remark: http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
It basically states that one can pass the registration of jersey resources to the jersey servlet. However i was not able to manage this using said method:
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
bind(GuiceResource.class);
Map<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
serve("/*").with(GuiceContainer.class, params);
}
}
});
Sadly I could not get more information about the registration process of jersey resources.
Any help would be appreciated. Of course I can provide additional info, if needed!
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我回答自己的问题变得相当标准,但我从 Guice 2 线程中找到了答案,但幸运的是它适用于 Guice 3 和 Jersey 1.8
就这样。
不要忘记将 params Map 传递给您的 GuiceContainer.class!
It becomes fairly standard that i answer my own question, but I found the answer from a Guice 2 Thread but fortunately it works with Guice 3 and Jersey 1.8
There you go.
Dont forget to pass the params Map to your GuiceContainer.class!