此内容没有您所选择的语言版本。
3.3. Bootstrapping a CXF Servlet in a WAR
Overview
A simple way to bootstrap Apache CXF in a WAR is to configure
web.xml
to use the standard CXF servlet, org.apache.cxf.transport.servlet.CXFServlet
.
Example
For example, the following
web.xml
file shows how to configure the CXF servlet, where all Web service addresses accessed through this servlet would be prefixed by /services/
(as specified by the value of servlet-mapping/url-pattern
):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>cxf</display-name> <description>cxf</description> <servlet> <servlet-name>cxf</servlet-name> <display-name>cxf</display-name> <description>Apache CXF Endpoint</description> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> </web-app>
cxf-servlet.xml file
In addition to configuring the
web.xml
file, it is also necessary to configure your Web services by defining a cxf-servlet.xml
file, which must be copied into the root of the generated WAR.
Alternatively, if you do not want to put
cxf-servlet.xml
in the default location, you can customize its name and location, by setting the contextConfigLocation
context parameter in the web.xml
file. For example, to specify that Apache CXF configuration is located in WEB-INF/cxf-servlet.xml
, set the following context parameter in web.xml
:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> ... <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/cxf-servlet.xml</param-value> </context-param> ... </web-app>
Reference
For full details of how to configure the CXF servlet, see .