在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时,再也找不到这个类了。
如何使用cxf创建servlet?
答案 0 :(得分:2)
我有一个简单的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;
}
}