我最近遇到了一種情況,我希望在單個Spring MVC Web應用程序中使用兩個單獨的Jersey應用程序。我創建了兩個映射到不同URI的獨立servlet,以及兩個具有相同路徑的獨立根資源類。多個Jersey應用程序具有相同的根資源路徑
應用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>
<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
}
澤西例外應用程序初始化期間拋出:
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 ,我期待這個工作。這在澤西島是不可能的,還是有不同的方法?
你的應用程序類是怎麼樣的?我的意思是public.api.rest.Application1和public.api.rest.Application2。你可以發佈該代碼嗎? – 2012-04-20 22:26:15
剛剛編輯帖子,添加App1Root和App2Root的代碼 – SkP 2012-04-26 14:36:15