Springboot整合cxf后不能访问controller,不能访问接口
参考版本
springboot 1.4.X <=========> cxf-spring-boot-starter-jaxws 3.1.X springboot 1.5.X <=========> cxf-spring-boot-starter-jaxws 3.2.X
成功集成cxf后,发现只有webservice服务可以正常使用,其他请求url全部无法正常访问。然后在cxf 配置文件中 WebServiceCxfCfg.java 更改此方法名:dispatcherServlet 改为 disServlet
//public ServletRegistrationBean dispatcherServlet() @Bean
public ServletRegistrationBean disServlet(){ return new ServletRegistrationBean(new CXFServlet() , "/services/*");
}
即可成功访问其他url
是因为 public ServletRegistrationBean dispatcherServlet() 把默认映射覆盖掉了,把这个名字改掉,控制类方法就能访问了。
整合的关键代码
maven
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.2.6</version>
</dependency>
CxfConfig
package com.xxx.xxx.common; import com.xxx.transfer.interceptor.IpAddressInInterceptor;
import com.xxx.transfer.webservice.DepartmentService;
import com.xxx.transfer.webservice.MedicalCardService;
import com.xxx.transfer.webservice.impl.DepartmentServiceImpl;
import com.xxx.transfer.webservice.impl.MedicalCardServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.annotation.Resource;
import javax.xml.ws.Endpoint; /**
* @Description: CXF配置类
* @date 2019/10/1617:39
*/
@Configuration
public class CxfConfig { @Resource
IpAddressInInterceptor ipAddressInInterceptor; /**
* 成功集成cxf后,发现只有webservice服务可以正常使用,其他请求url全部无法正常访问,是因为 public ServletRegistrationBean dispatcherServlet() 把默认映射覆盖掉了,把这个名字改掉,控制类方法就能访问了
* 修改dispatcherServlet为disServlet
*/
@Bean
public ServletRegistrationBean disServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
} @Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
} @Bean
public MedicalCardService medicalCardService() {
return new MedicalCardServiceImpl();
} @Bean
public DepartmentService departmentService() {
return new DepartmentServiceImpl();
} /**
* 诊疗卡信息查询
*
* @return
*/
@Bean
public Endpoint getPatInfo() {
EndpointImpl endpoint = new EndpointImpl(springBus(), medicalCardService());
endpoint.getInInterceptors().add(ipAddressInInterceptor);
endpoint.publish("/pat");
return endpoint;
} /**
* 获取挂号科室
*
* @return
*/
@Bean
public Endpoint getDeptList() {
EndpointImpl endpoint = new EndpointImpl(springBus(), departmentService());
//添加校验拦截器
endpoint.getInInterceptors().add(ipAddressInInterceptor);
endpoint.publish("/dept");
return endpoint;
}
}
service
package com.xxx.xxx.webservice; import javax.jws.WebParam;
import javax.jws.WebService; /**
* @Description: 获取挂号科室
* @date 2019/10/1617:35
*/
@WebService(
// 暴露服务名称
name = "getDeptList",
// 命名空间,一般是接口的包名倒序
targetNamespace = "http://webservice.transfer.webservice.com"
)
public interface DepartmentService { /**
* 获取挂号科室
*/
public String getDeptList(
// xxxx
@WebParam(name = "xxx") String xxx,
// xxx
@WebParam(name = "xxx") String xxx,
// xxx
@WebParam(name = "xxx") String xxx,
// xxx
@WebParam(name = "xxx") String xxx
);
}
package com.xxx.xxx.webservice.impl; import com.xxx.xxx.webservice.DepartmentService; import javax.jws.WebService; /**
* @Description:
* @date 2019/10/1617:38
*/
@WebService(
// 与接口中指定的name一致
serviceName = "getDeptList",
// 与接口中的命名空间一致,一般是接口的包名倒
targetNamespace = "http://webservice.transfer.webservice.com",
// 接口地址
endpointInterface = "com.xxx.transfer.webservice.DepartmentService"
)
public class DepartmentServiceImpl implements DepartmentService {
@Override
public String getDeptList(String guahaofs, String riqi, String guahaobc, String guahaolb) {
return "success";
}
}
Springboot整合cxf后不能访问controller,不能访问接口的更多相关文章
- webService学习之路(三):springMVC集成CXF后调用已知的wsdl接口
webService学习之路一:讲解了通过传统方式怎么发布及调用webservice webService学习之路二:讲解了SpringMVC和CXF的集成及快速发布webservice 本篇文章将讲 ...
- springMVC集成CXF后调用已知的wsdl接口
本文转载自:https://www.cnblogs.com/xiaochangwei/p/5400303.html 本篇文章将讲解SpringMVC+CXF环境下,怎么调用其他系统通过webServi ...
- springboot 整合 CXF 版本异常 java.lang.NoClassDefFoundError:ServletRegistrationBean
在使用SpringBoot 项目整合webservice组件 CXF的时候,在启动时,抛出异常如下,查阅资料初步判断为版本问题.升级到高版本后正常启动. cxf 刚开始使用版本 3.1.7 后更新为 ...
- SpringBoot整合cxf发布webService
1. 看看项目结构图 2. cxf的pom依赖 1 <dependency>2 <groupId>org.apache.cxf</groupId>3 <art ...
- springboot整合websocket后运行测试类报错:javax.websocket.server.ServerContainer not available
springboot项目添加websocket依赖后运行测试类报如下错误: org.springframework.beans.factory.BeanCreationException: Error ...
- spring-boot整合Cxf的webservice案例
1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.Maven Plugin管理 <?xml version="1.0&q ...
- springboot整合websocket后打包报错:javax.websocket.server.ServerContainer not available
项目整合了websocket以后,打包多次都没有成功,原来是报错了,报错内容如下: Error starting ApplicationContext. To display the conditio ...
- 十六、springboot整合Spring-data-jpa(二)之通用DAO接口与添加自定义方法
@NoRepositoryBean:Spring Data Jpa在启动时就不会去实例化BaseRepository这个接口 1.通用接口: import org.springframework.da ...
- 解决在Filter中读取Request中的流后,后续controller或restful接口中无法获取流的问题
首先我们来描述一下在开发中遇到的问题,场景如下: 比如我们要拦截所有请求,获取请求中的某个参数,进行相应的逻辑处理:比如我要获取所有请求中的公共参数 token,clientVersion等等:这个时 ...
随机推荐
- ELK之es常用查询语句
参考:https://www.cnblogs.com/kyleinjava/p/10497042.html https://blog.csdn.net/luanpeng825485 ...
- 16、vue引入echarts,划中国地图
vue引入echarts npm install echarts --save main.js引入 import echarts from 'echarts' Vue.prototype.$echar ...
- puppeteer-firefox 开启扩展
puppeteer-firefox安装扩展 puppeteer-firefox 目前已经有许多人在投入开发工作,但是和chrome的launch打开扩展api不一致,在chrome中,我们可以很容易配 ...
- zero copy图解
原文链接:https://www.jianshu.com/p/8c6b056f73ce 1 传统的IO读写 传统的IO读写有两种方式:IO终端和DMA.他们各自的原理如下. 1.1 IO中断原理 ...
- python selenium学习
selenium是一个python模块,具有自动化模拟浏览器的功能 selenium的中文文档地址:http://selenium-python-zh.readthedocs.io/en/latest ...
- Beginning Linux Programming 学习--chapter 17 Programming KDE using QT
KDE: KDE,K桌面环境(K Desktop Environment)的缩写.一种著名的运行于 Linux.Unix 以及FreeBSD 等操作系统上的自由图形桌面环境,整个系统采用的都是 Tro ...
- torch.Tensor和numpy.ndarray
1. torch.Tensor和numpy.ndarray相互转换 import torch import numpy as np # <class 'numpy.ndarray'> np ...
- FZU2018级算法第五次作业 missile(排序+枚举)
在解题报告之前,首先对同一次作业中另外一题(求逆序对)某人在未经冰少允许情况下,擅自登录冰少账号,原模原样剽窃冰少代码,并且最终还被评为优秀作业的行为表示严正抗议! 题目大意: 二维平面上给出 n 个 ...
- Redis--zset类型操作命令
有序集合类型 zset (sorted set ) redis 有序集合zset和集合set一样也是string类型元素的集合,且不允许重复的成员. 不同的是 zset 的每个元素都会关联一个分数(分 ...
- C++11<functional>深度剖析:背景、原理、接口与实现
自C++11以来,C++标准每3年修订一次.C++14/17都可以说是更完整的C++11:即将到来的C++20也已经特性完整了. C++11已经有好几年了,它的年龄比我接触C++的时间要长10倍不止吧 ...