java cxf 双向通讯_CXF 在spring boot 2 发布多个服务
0. 問題來源
之前配置cxf服務端都是在spring 3以下,后來使用spring mvc 還都是基于xml的配置文件模式,在springboot模式下,實現起來更為簡單了。此次記錄下spring boot 2下的實現方式。
1. 準備工作
項目中,直接拉入spring boot cxf相關依賴
org.apache.cxf
cxf-spring-boot-starter-jaxws
3.2.4
系統環境中安裝解壓版的cxf代碼(用于服務端生成代碼)
我這里使用的版本是 apache-cxf-3.2.7,不再贅述,解壓,配置環境變量
2. 具體細節
生成客戶端代碼,然后一股腦懟到項目里
wsdl2java -encoding utf-8 -d 你的目錄 -client
創建CxfConfig.java 在項目中
package com.account.ibm.sync.config;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
import com.cmcc.mss.sb_eas_eas_importclaimchannelserviceinfosrv.SBEASEASImportClaimChannelServiceInfoSrv;
import com.cmcc.soa.osb_bp_soa_hq_importtransmissinotifysrv.OSBBPSOAHQImportTransmissiNotifySrv;
/**
* @description cxf配置 用于發布服務所用的類
* @author fg
* @date 2019年1月29日
*/
@Configuration
public class CxfConfig {
@Autowired
private SpringBus bus;
@Bean
@Qualifier("oSBBPSOAHQImportTransmissiNotifySrv")
public Endpoint importTransmissiNotifySrv(OSBBPSOAHQImportTransmissiNotifySrv oSBBPSOAHQImportTransmissiNotifySrv) {
EndpointImpl endpoint = new EndpointImpl(bus, oSBBPSOAHQImportTransmissiNotifySrv);
endpoint.publish("/OSB_BP_SOA_HQ_ImportTransmissiNotifySrv");
return endpoint;
}
@Bean
@Qualifier("sBEASEASImportClaimChannelServiceInfoSrv")
public Endpoint importClaimChannelServiceInfoSrv(SBEASEASImportClaimChannelServiceInfoSrv sBEASEASImportClaimChannelServiceInfoSrv) {
EndpointImpl endpoint = new EndpointImpl(bus, sBEASEASImportClaimChannelServiceInfoSrv);
endpoint.publish("/SB_EAS_EAS_ImportClaimChannelServiceInfoSrv");
return endpoint;
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
SpringBus springBus = new SpringBus();
LoggingFeature logFeature = new LoggingFeature();
logFeature.setPrettyLogging(true);
logFeature.initialize(springBus);
springBus.getFeatures().add(logFeature);
return springBus;
}
}
我這里是兩個服務,因此是聲明兩個@Bean Endpoint,而不是網上一些說法配置兩個CxfConfig
2. 測試
訪問如下地址,可以看到兩個接口
http://localhost/你的項目名/services/
總結
以上是生活随笔為你收集整理的java cxf 双向通讯_CXF 在spring boot 2 发布多个服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VMware——安装CentOS
- 下一篇: Maven中央仓库地址和Nexus 下