1.首先准备好pom文件
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.0</version>
</dependency>
2.在web.xml文件加入如下配置
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
3.配置springmvc-cxf.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/jaxws">
<!-- 引cxf的一些核心配置 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="orderWS"
implementor="cn.ljj.service.impl.OrderWSImpl"
address="/orderws">
<!-- <jaxws:inInterceptors>
<bean class="cn.ljj.interceptor.CheckUserInterceptor"></bean>
</jaxws:inInterceptors> -->
</jaxws:endpoint>
</beans>
4.webService代码实例
package cn.ljj.bean;
public class Order {
private int id;
private String name;
private double price;
public Order(int id, String name, double price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
public Order() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Order [id=" + id + ", name=" + name + ", price=" + price + "]";
}
}
-------------------------------------------------------------------------------------------------------------
package cn.ljj.service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import cn.ljj.bean.Order;
@WebService
public interface OrderWS {
@WebMethod
public Order getOrderById(int id);
}
---------------------------------------------------------------------------------------------------------------
package cn.ljj.service.impl;
import javax.jws.WebService;
import cn.ljj.bean.Order;
@WebService
public class OrderWSImpl implements OrderWS {
public OrderWSImpl() {
System.out.println("OrderWSImpl()");
}
@Override
public Order getOrderById(int id) {
System.out.println("server getOrderById() "+id);
return new Order(id, "飞机", 10000000);
}
}
---------------------------------------------------------------------------------
5.这样访问"项目路径+/orderws?wsdl“就可以访问自动生成的.wsdl文件了