700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > SpringBoot2.6.5整合CXF框架

SpringBoot2.6.5整合CXF框架

时间:2021-03-14 18:27:08

相关推荐

SpringBoot2.6.5整合CXF框架

最近接手了一个项目,要实现WebService接口调用的功能。java开发WebService的框架主要包括axis2和CXF,CXF属于轻量级WebService的框架,支持spring集成;axis2相较来说有点笨重,和spring配合使用不太友好,所以此次选择CXF进行开发。

1. 服务端

1.1 引入依赖

创建SpringBoot项目,引入CXF所需依赖,pom文件如下:

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.5</version><relativePath/> </parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!-- CXF webservice --><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxws</artifactId><version>3.4.3</version><exclusions><exclusion><groupId>javax.validation</groupId><artifactId>validation-api</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.4.3</version></dependency><!-- CXF webservice --></dependencies>

1.2 CXF配置

package .cxf.config;import .cxf.service.TSAService;import org.apache.cxf.Bus;import org.apache.cxf.jaxws.EndpointImpl;import org.apache.cxf.transport.servlet.CXFServlet;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import javax.xml.ws.Endpoint;@Configurationpublic class WebServiceConfig {@Autowiredprivate TSAService service;@Autowiredprivate Bus bus;/*** 设置Webservice接口访问前缀* @return*/@Bean(name = "cxfServlet")public ServletRegistrationBean dispatcherServlet(){return new ServletRegistrationBean(new CXFServlet(),"/cxf/*");}/*** 将Webservice接口进行暴露* 访问路径:ip+端口+/cxf+/webservice* @return*/@Beanpublic Endpoint userEndpoint(){EndpointImpl endpoint=new EndpointImpl(bus,service);endpoint.publish("/webservice");return endpoint;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。