如何创建 CXFServlet?

How to create the CXFServlet?

cxf-3.1.0 之前,可以使用 new org.apache.cxf.transport.servlet.CXFServlet() 实例化 servlet,或者通过 web.xml 配置:

  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>
       org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup> 
  </servlet>

但是现在升级到3.1.0后,class就找不到了

如何使用 cxf 创建 servlet?

我有一个简单的 spring 引导应用程序,它可以与 CXFServlet 一起正常工作 - 这是 pom.xml 的摘录:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>demo.DemoApplication</start-class>
    <java.version>1.7</java.version>
    <cxf.version>3.1.0</cxf.version>
</properties>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>

我只是创建了新的 servlet,比如

@SpringBootApplication
@ImportResource({"classpath:/cxf-servlet.xml" })
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public ServletRegistrationBean cxfServlet() {
        org.apache.cxf.transport.servlet.CXFServlet cxfServlet = new org.apache.cxf.transport.servlet.CXFServlet();
        ServletRegistrationBean servletDef = new ServletRegistrationBean(cxfServlet, "/cxf/*");
        servletDef.setLoadOnStartup(1);
        return servletDef;
    }
}