sts 创建webservice项目_用 Eclipse 开发 WebService 项目

本文介绍了如何在Spring Tool Suite (STS) 中利用Apache CXF创建一个SpringBoot WebService项目。首先,安装Tomcat和CXF,然后在STS中创建Top down java bean web service,设置HTTP URL和服务器。接着,将生成的服务类复制到项目中,并通过EndpointConfig配置CXF服务发布。在整合Spring时遇到PolicyException问题,通过禁用WSPolicyFeature解决。
摘要由CSDN通过智能技术生成

1、安装tomcat

2、安装CXF

一、为新渠道webservice加入到项目中

首先,创建一个springboot项目,名为webservice-baffle(附件中)。

第二步,新建web service 服务端

右击webservice-baffle项目,新建“other”,在弹出框中选择“web service”,出现如下弹出框

截图中:

1、web service type:选择 Top down java bean web service

2、web service的http url

3、选择tomcat,如果没有环境,自己下载tomcat并安装配置下

4、选择apache CXF 2.x,如果没有,自己下载和安装下

下一步,出现如下提示框,默认到完成。

最后,生成一个WebServiceProject项目。

第三步:将生产的java类拷贝到webservice-baffle项目中:

第四步:注册webservice接口到servlet中:

该操作的代码在com.xxx.xxx.config.EndpointConfig.java

@Configurationpublic classCxfConfig {

@Autowiredprivate Bus bus; //private SpringBus bus;

@AutowiredprivateCommonService commonService;//配置CXF服务发布,默认服务是在host:port/services/发布地址//访问地址http://127.0.0.1:8080/Service/common?wsdl

@BeanpublicEndpoint another_endpoint() {

EndpointImpl endpoint= newEndpointImpl(bus, commonService);

endpoint.publish("/common"); //发布地址

returnendpoint;

}//访问地址http://127.0.0.1:8080/Service/hello?wsdl

@BeanpublicEndpoint endpoint() {

EndpointImpl endpoint= new EndpointImpl(bus, newHelloServiceImpl());

endpoint.publish("/hello"); //发布地址

returnendpoint;

}

完成。

问题:

1、与Spring整合问题

Caused by: org.apache.cxf.ws.policy.PolicyException: These policy alternatives can not be satisfied:

{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SupportingTokens

{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}UsernameToken

at org.apache.cxf.ws.policy.AssertionInfoMap.checkEffectivePolicy(AssertionInfoMap.java:166)

at org.apache.cxf.ws.policy.PolicyVerificationInInterceptor.handle(PolicyVerificationInInterceptor.java:101)

解决方法

esb-server.xml配置增加

@Bean(name =Bus.DEFAULT_BUS_ID)publicSpringBus springBus() {

SpringBus springBus= new SpringBus();

WSPolicyFeature wpf = new WSPolicyFeature();

wpf.setEnabled(false);

Collection features = springBus.getFeatures();

features.add(wpf);

returnspringBus;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值