]
一.创建两个springBoot+gradle项目,将以下依赖放入build.gradle中
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//引入cxf框架
compile 'org.apache.cxf:cxf-spring-boot-starter-jaxws:3.2.6'
}
二.首先创建webService服务端
1.创建一个UserService接口(注意加上@webService才能成为服务端)
@WebService(name = "UserService", // 暴露服务名称
targetNamespace = "http://service.wsserver.meng.com" // 命名空间,一般是接口的包名倒序
)
public interface UserService {
@WebMethod//标注该方法为webservice暴露的方法,用于向外公布,它修饰的方法是webservice方法,去掉也没影响的,类似一个注释信息。
@WebResult(name="int",targetNamespace="")//name属性为返回值类型,targetNamespace可以为空
//模拟两个数相加
public int add(@WebParam(name = "w1")int w1,@WebParam(name = "w2")int w2);
}
2.创建UserService的实现类UserServiceImpl
@WebService(serviceName="UserService",//对外发布的服务名
targetNamespace = "http://service.wsserver.meng.com",//指定你想要的名称空间,通常使用使用包名反转
endpointInterface="com.meng.wsserver.service.UserServi