我最近遇到了一种情况,我想在一个 Spring MVC Web 应用程序中使用两个独立的 Jersey 应用程序。我创建了两个映射到不同 URI 的独立 servlet,以及两个具有相同路径的独立根资源类。
应用程序 1 Servlet:
<servlet>
<servlet-name>JerseyServlet1</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>public.api.rest.Application1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet1</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
应用 2 小服务程序:
<servlet>
<servlet-name>JerseyServlet2</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>private.api.rest.Application2</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JerseyServlet2</servlet-name>
<url-pattern>/internal/*</url-pattern>
</servlet-mapping>
应用1:
package public.api.rest;
public class Application1 extends PackagesResourceConfig {
public Application1(){
super(Application1.class.getPackage().getName());
}
}
应用 2:
package private.api.rest;
public class Application2 extends PackagesResourceConfig {
public Application2(){
super(Application2.class.getPackage().getName());
}
}
应用程序 1 根资源:
package public.api.rest;
@Path("release-1")
@Component
@Scope("request")
public class App1Root{
//resource methods
}
应用程序 2 根资源:
package private.api.rest;
@Path("release-1")
@Component
@Scope("request")
public class App2Root{
//resource methods
}
应用程序初始化期间抛出的 Jersey 异常:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Conflicting URI templates. The URI template /release-1 for root resource class private.api.rest.App2Root and the URI template /release-1 transform to the same regular expression /release-1(/.*)?
由于这些是两个独立的应用程序和两个独立的 servlet,我期待它能够工作。这在泽西岛是不可能的还是有不同的方法?