我記錄的是工作中所用到的,只是把我看到的理解的記錄一下,僅供參考(...),所記錄的不是特別詳細,所以我找到了一篇自認爲特別詳細的介紹:
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/
點擊上面的鏈接可以看到具體的內容: