Springboot整合cxf后不能访问controller,不能访问接口

参考版本

1springboot 1.4.X  <=========>  cxf-spring-boot-starter-jaxws 3.1.X 2 3springboot 1.5.X  <=========>  cxf-spring-boot-starter-jaxws 3.2.X

成功集成cxf后,发现只有webservice服务可以正常使用,其他请求url全部无法正常访问。然后在cxf 配置文件中 WebServiceCxfCfg.java 更改此方法名:dispatcherServlet 改为 disServlet

1//public ServletRegistrationBean dispatcherServlet() 2 3@Bean 4public ServletRegistrationBean disServlet(){ 5 6 return new ServletRegistrationBean(new CXFServlet() , "/services/*"); 7}

即可成功访问其他url

是因为 public ServletRegistrationBean dispatcherServlet() 把默认映射覆盖掉了,把这个名字改掉,控制类方法就能访问了。

整合的关键代码

maven

1<dependency> 2  <groupId>org.apache.cxf</groupId> 3  <artifactId>cxf-rt-frontend-jaxws</artifactId> 4  <version>3.2.6</version> 5</dependency>

CxfConfig

1package com.xxx.xxx.common; 2 3import com.xxx.transfer.interceptor.IpAddressInInterceptor; 4import com.xxx.transfer.webservice.DepartmentService; 5import com.xxx.transfer.webservice.MedicalCardService; 6import com.xxx.transfer.webservice.impl.DepartmentServiceImpl; 7import com.xxx.transfer.webservice.impl.MedicalCardServiceImpl; 8import org.apache.cxf.Bus; 9import org.apache.cxf.bus.spring.SpringBus; 10import org.apache.cxf.jaxws.EndpointImpl; 11import org.apache.cxf.transport.servlet.CXFServlet; 12import org.springframework.boot.web.servlet.ServletRegistrationBean; 13import org.springframework.context.annotation.Bean; 14import org.springframework.context.annotation.Configuration; 15 16import javax.annotation.Resource; 17import javax.xml.ws.Endpoint; 18 19/** 20 * @Description: CXF配置类 21 * @date 2019/10/1617:39 22 */ 23@Configuration 24public class CxfConfig { 25 26 @Resource 27 IpAddressInInterceptor ipAddressInInterceptor; 28 29 /** 30 * 成功集成cxf后,发现只有webservice服务可以正常使用,其他请求url全部无法正常访问,是因为 public ServletRegistrationBean dispatcherServlet() 把默认映射覆盖掉了,把这个名字改掉,控制类方法就能访问了 31 * 修改dispatcherServlet为disServlet 32 */ 33 @Bean 34 public ServletRegistrationBean disServlet() { 35 return new ServletRegistrationBean(new CXFServlet(), "/webservice/*"); 36 } 37 38 @Bean(name = Bus.DEFAULT_BUS_ID) 39 public SpringBus springBus() { 40 return new SpringBus(); 41 } 42 43 @Bean 44 public MedicalCardService medicalCardService() { 45 return new MedicalCardServiceImpl(); 46 } 47 48 @Bean 49 public DepartmentService departmentService() { 50 return new DepartmentServiceImpl(); 51 } 52 53 /** 54 * 诊疗卡信息查询 55 * 56 * @return 57 */ 58 @Bean 59 public Endpoint getPatInfo() { 60 EndpointImpl endpoint = new EndpointImpl(springBus(), medicalCardService()); 61 endpoint.getInInterceptors().add(ipAddressInInterceptor); 62 endpoint.publish("/pat"); 63 return endpoint; 64 } 65 66 /** 67 * 获取挂号科室 68 * 69 * @return 70 */ 71 @Bean 72 public Endpoint getDeptList() { 73 EndpointImpl endpoint = new EndpointImpl(springBus(), departmentService()); 74 //添加校验拦截器 75 endpoint.getInInterceptors().add(ipAddressInInterceptor); 76 endpoint.publish("/dept"); 77 return endpoint; 78 } 79}

service

1package com.xxx.xxx.webservice; 2 3import javax.jws.WebParam; 4import javax.jws.WebService; 5 6/** 7 * @Description: 获取挂号科室 8 * @date 2019/10/1617:35 9 */ 10@WebService( 11 // 暴露服务名称 12 name = "getDeptList", 13 // 命名空间,一般是接口的包名倒序 14 targetNamespace = "http://webservice.transfer.webservice.com" 15) 16public interface DepartmentService { 17 18 /** 19 * 获取挂号科室 20 */ 21 public String getDeptList( 22 // xxxx 23 @WebParam(name = "xxx") String xxx, 24 // xxx 25 @WebParam(name = "xxx") String xxx, 26 // xxx 27 @WebParam(name = "xxx") String xxx, 28 // xxx 29 @WebParam(name = "xxx") String xxx 30 ); 31} 32 33package com.xxx.xxx.webservice.impl; 34 35import com.xxx.xxx.webservice.DepartmentService; 36 37import javax.jws.WebService; 38 39/** 40 * @Description: 41 * @date 2019/10/1617:38 42 */ 43@WebService( 44 // 与接口中指定的name一致 45 serviceName = "getDeptList", 46 // 与接口中的命名空间一致,一般是接口的包名倒 47 targetNamespace = "http://webservice.transfer.webservice.com", 48 // 接口地址 49 endpointInterface = "com.xxx.transfer.webservice.DepartmentService" 50) 51public class DepartmentServiceImpl implements DepartmentService { 52 @Override 53 public String getDeptList(String guahaofs, String riqi, String guahaobc, String guahaolb) { 54 return "success"; 55 } 56}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )