我正在尝试使用apache cxf(非spring)实现rest webservice。我已经配置了我的web.xml并添加了一个端点地址,它工作正常,但现在我想再添加一个端点地址或一个服务类,我无法做到,因为第二个覆盖了第一个。 我的web.xml就像这样
<servlet>
<display-name>CXFNonSpringJaxrsServlet</display-name>
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>abc</param-value>
</init-param>
<init-param>
<param-name>jaxrs.address</param-name>
<param-value>/abc</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<display-name>CXFNonSpringJaxrsServlet</display-name>
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>xyz</param-value>
</init-param>
<init-param>
<param-name>jaxrs.address</param-name>
<param-value>/xyz</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
答案 0 :(得分:3)
您可以这样做以拥有多个端点:
的web.xml
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<!-- Multiple resource classes separated with space -->
<param-value>
com.gsdev.Resource1 com.gsdev.Resource2
com.ttdev.bs.BookSelectionsResource
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
资源类将如下:
@Path("endpoint1/")
public class Resource1
@Path("endpoint2/")
public class Resource2
现在您有不同的端点
http://host:port/webapp/services/endpoint1/
http://host:port/webapp/services/endpoint2/