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等等:这个时 ...
随机推荐
- python flask框架学习(二)——第一个flask程序
第一个flask程序 学习自:知了课堂Python Flask框架——全栈开发 1.用pycharm新建一个flask项目 2.运行程序 from flask import Flask # 创建一个F ...
- gen语言
概率编程语言(PPL)领域正经历着机器学习技术快速发展带来的奇迹般的复兴.在短短的几年里,PPL 已经从一个模糊的统计研究领域发展出十几个活跃的开源方案.最近,麻省理工学院(MIT)的研究人员推出了一 ...
- 【线段树】HDU 1166 敌兵布阵
这道题目是线段树里面最基础的单点更新问题. 设计的知识点包括线段树的单点更新和区间查询. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 G++ ...
- 使用mousedown、mousemove、mouseup实现拖拽效果
如何实现一个元素的拖拽效果,使用原生的js实现,习惯了jquery的同学们,你们自己写了吗?N久使用mvvm框架,不写jquery的东西,感觉自己完全不会了. 话不多说,直接上code.本例子以简单的 ...
- 04点睛Spring4.1-资源调用
转发:https://www.iteye.com/blog/wiselyman-2210666 4.1 Resource spring用来调用外部资源数据的方式 支持调用文件或者是网址 在系统中调用p ...
- sudo启动程序引发的进程个数不对
这几天把自己负责的服务改成了多进程模型,然后使用sudo来启动进程,示例程序如下: int main(void) { fork(); while(1); } 编译: `gcc ...
- Selenium IDE命令
Selenium IDE中提供了丰富的操作命令,在Selenium IDE的Command的下拉列表框中可以选择使用这些命令. 下面介绍一些常用命令的使用. 1.open open(url) 在浏览器 ...
- Yii2性能优化
https://www.yiiframework.com/doc/guide/2.0/zh-cn/tutorial-performance-tuning 性能优化 有许多因素影响你的 Web 应用程序 ...
- Windows Server 2012 安装 .NET 3.5 解决办法
我遇到的每台Windows Server 2012都会遇到无法通过控制面板进行.net3.5安装的问题,在网上找了很多办法都不适合自己,最后研究出来一个办法就是 1.首先从镜像提取sxs文件放置到一个 ...
- flask 密钥问题
RuntimeError RuntimeError: The session is unavailable because no secret key was set. Set the secret_ ...