【发布时间】:2013-03-17 21:57:29
【问题描述】:
我确实有以下配置作为 Guice 模块(而不是 web.xml)
public class RestModule extends JerseyServletModule {
@Override
protected void configureServlets() {
install(new JpaPersistModule("myDB"));
filter("/*").through(PersistFilter.class);
bind(CustomerList.class);
bind(OrdersList.class);
bind(MessageBodyReader.class).to(JacksonJsonProvider.class);
bind(MessageBodyWriter.class).to(JacksonJsonProvider.class);
ImmutableMap<String, String> settings = ImmutableMap.of(
JSONConfiguration.FEATURE_POJO_MAPPING, "true"
);
serve("/*").with(GuiceContainer.class, settings);
}
}
为 REST 端点提供服务已经非常有效了。
当用户请求 http://example.com/ 时,我想从 /webapp/index.html 提供一个静态 html 文件
以及http://example.com/customers 或http://example.com/orders 的其余服务
我不使用 web.xml。网络服务器是码头
【问题讨论】:
-
我知道stackoverflow.com/questions/10808610/… 中有类似的答案,但我真的想避免使用 /services/ 前缀
-
安德烈亚斯,你找到解决办法了吗?我已经为此苦苦挣扎了好几个小时了。我已经尝试了从在 guice 社区发布的各种正则表达式的 serveRegex 到这个解决方案 (stackoverflow.com/a/3593513/695318) 到使用 tuckey UrlRewriteFilter 的所有方法,但我每次都失败了。最后,由于您的问题,我找到了 condit 的帖子,并且运行良好。如果您使用过其他解决方案,我会很好奇您是如何解决的。
标签: jersey jetty guice guice-servlet