我记录的是工作中所用到的,只是把我看到的理解的记录一下,仅供参考(...),所记录的不是特别详细,所以我找到了一篇自认为特别详细的介绍:
https://blog.csdn.net/hgx_suiyuesusu/article/details/88918192
https://blog.csdn.net/csdn_gia/article/details/54863549
https://www.cnblogs.com/yongfeng/archive/2013/01/30/2883146.html
感觉把我想写的都写了,哈哈
我也是菜鸟,需要不断的积累和学习,加油.
导入cxf的依赖:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.6</version>
</dependency>
我们这里主要是通过注解配置,web service的配置类
/**
* webService配置类
* @author 这是公司大佬写的
*/
@Configuration
public class CxfConfig {
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new CXFServlet(), "/services/*");
//ServletName默认值为首字母小写,即myServlet 访问的时候就是需要访问这个localhost:8081/项目名/services
}
@Bean
public MakeSealSystem makeSealSystem(){ // 这里是webService实现类
return new MakeSealSystem();
}
@Bean
public Endpoint makeSealEndpoint() { // 这里是访问界面中的地址
EndpointImpl endpoint = new EndpointImpl(springBus, makeSealSystem());
endpoint.publish("/makeSealSystemService");
return endpoint;
}
@Bean
public MakeSealSystemProcess makeSealSystemProcess() { // 这里是调用webservice实现类中的类
return new MakeSealSystemProcess();
}
@Autowired
SpringBus springBus; // 这个是EndpointImpl实现类所需要的
}
上面注入的springBus主要是这个功能:
它的主要责任是提供对不同扩展名(例如DestinationFactoryManager,ConduitFactoryManager,BindingFactoryManager等)的访问。 根据总线的实现,它也可能负责连接CXF内部。
web service的实现类:
/**
* 制作系统webService实现类
* @author 这是公司美丽的小姐姐写的
*/
@WebService
public class MakeSealSystem {
// 这个里面的makeSealSystemProcess是一个具体的实现逻辑的类
@WebMethod
public String applySealCode(@WebParam(name = "requestStr") String requestStr) throws Exception {
long beginTime=System.currentTimeMillis();
String result = ((MakeSealSystemProcess) Util.getBean("makeSealSystemProcess")).applySealCode(requestStr,beginTime,getRequest());
return result;
}
private HttpServletRequest getRequest() {
MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
return request;
}
@Resource
private WebServiceContext context;
}
看访问的结果:http://localhost:8081/项目名称/services/
点击上面的链接可以看到具体的内容: