导入pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
1 创建WebServiceConfig配置类
@Configuration
public class WebServiceConfig {
//创建websocket的Endpoint
@Bean
public Endpoint getEndpoint() {
MyService serviceImpl=new MyServiceImpl();
Endpoint publish = EndpointImpl.publish(“http://localhost:8080/show”,serviceImpl);
return publish;
}
}
2 创建服务接口和服务实现类
接口
@WebService
public interface MyService {
@WebResult
@WebMethod
String show();
}
实现类
/**
-
@description 在當前的实现类中添加注解@WebService
-
@author hy
-
@date 2019-08-15
*/
@WebService(endpointInterface = “com.hy.springboot.webservice.demo.service.MyService”)
public class MyServiceImpl implements MyService{public String show() {
System.out.println(“MyServiceImpl中的show方法被调用!”);
return “【调用成功!】”;
}
}