一、pom文件设置
@Configuration
public class WebServiceConfig {
@Autowired
private Bus bus;
@Autowired
private TestWebService testWebService;
@Autowired
private AuthHandler authHandler;
@Bean
public ServletRegistrationBean disServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, testWebService);
// 鉴权校验
endpoint.getHandlers().add(authHandler);
endpoint.publish("/test");
return endpoint;
}
}
三、service类
@WebService(targetNamespace = "http://service.springboot.dreamboat.com.cn")
public interface HelloWebService {
@WebMethod
@WSDLDocumentation( "测试webservice方法")
RestResult<String> testWebServiceMethod(@WebParam(name = "methodParam") String methodParam);
}
@Slf4j
@WebService(serviceName = "TestWebService",
targetNamespace = "http://service.springboot.dreamboat.com.cn",
endpointInterface = "cn.com.dreamboat.springboot.service.HelloWebService"
)
@Component
public class HelloWebServiceImpl implements HelloWebService {
@Override
public RestResult<String> testWebServiceMethod(String methodParam) {
// 业务...
return RestResult.success(methodParam);
}
}
四、打完收工~
原文:https://www.cnblogs.com/timeflying/p/12897548.html