同一WAR中的多个JAX-RS应用程序

我有

@ApplicationPath("/resourcesP") public class RestfulPrediction extends Application { @Override public Set<Class> getClasses() { Set<Class> set = new HashSet<Class>(); set.add(PredictionsRS.class); return set; } } 

 @ApplicationPath("/resourcesA") public class RestfulAdage extends Application { @Override public Set<Class> getClasses() { Set<Class> set = new HashSet<Class>(); set.add(Adages.class); return set; } } 

两个不同的ApplicationPath和类如下。

 @Path("/") public class service.Adages {} @Path("/") public class webservices.PredictionsRS {} 

它们都在不同的ApplicationPath中声明。 我正在使用Jersey,web.xml中的配置看起来像

   jersey com.sun.jersey.spi.container.servlet.ServletContainer  com.sun.jersey.config.property.packages  service webservices   1  

而且我得到了

严重:冲突的URI模板。 URI模板/用于根资源类service.Adages和URI模板/转换为相同的正则表达式(/.*)?

为什么我有两个不同的ApplicationPath这个exception在启动时出现?

如果我在param-value中取出一个包有效,那么如果我更改了其中一个@Path注释,那么这对我的配置有问题吗?

我正在使用Jersey 1.10。 谢谢大家。

您没有在web.xml定义JAX-RS应用程序。 请尝试以下方法:

  full.name.RestfulAdage   full.name.RestfulPrediction   full.name.RestfulPrediction /resourcesP/*   full.name.RestfulPrediction /resourcesA/*  

并从代码中删除@ApplicationPAth注释。

我用Jersey 2.7,servlet容器3.0检查了上面的代码,它可以工作。 如果还有这个bug,请尝试升级到Jersey 1.17(不应该改变Jersey 1.10的任何行为,而是修改bug)并最终使用servlet容器3.0。

UPDATE

在检查可能性之后,以下配置与Jersey 1.17一起使用

   jersey com.sun.jersey.spi.container.servlet.ServletContainer  com.sun.jersey.config.property.packages  com.koitoer.webservices   1  

似乎旧版Jersey中的规范中存在错误,这种错误会将引用圈回并标记为重复的端点。 使用上面的配置加载两个端点没有任何问题。

8/04/2014 09:13:40 PM com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer addServletWithApplication INFO:注册名为com.koitoer.webservices.chapter2.service2.RestfulPrediction的Jersey servlet应用程序servlet映射, / resourcesP / * ,与同名的Application类

8/04/2014 09:13:40 PM com.sun.jersey.server.impl.container.servlet.JerseyServletContainerInitializer addServletWithApplication INFO:在servlet映射中注册名为com.koitoer.webservices.chapter2.RestfulAdage的Jersey servlet应用程序, / resourcesA / * ,与Application名称相同的类

您应该在webapp中有一个javax.ws.rs.core.Application子类,然后在service.Adageswebservices.PredictionsRS资源类型上使用不同的@Path注释值。 AFAIK,在JEE6容器中,你不允许有2个这样的子类……