参考版本

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,不能访问接口的更多相关文章

  1. webService学习之路(三):springMVC集成CXF后调用已知的wsdl接口

    webService学习之路一:讲解了通过传统方式怎么发布及调用webservice webService学习之路二:讲解了SpringMVC和CXF的集成及快速发布webservice 本篇文章将讲 ...

  2. springMVC集成CXF后调用已知的wsdl接口

    本文转载自:https://www.cnblogs.com/xiaochangwei/p/5400303.html 本篇文章将讲解SpringMVC+CXF环境下,怎么调用其他系统通过webServi ...

  3. springboot 整合 CXF 版本异常 java.lang.NoClassDefFoundError:ServletRegistrationBean

    在使用SpringBoot 项目整合webservice组件 CXF的时候,在启动时,抛出异常如下,查阅资料初步判断为版本问题.升级到高版本后正常启动. cxf 刚开始使用版本  3.1.7 后更新为 ...

  4. SpringBoot整合cxf发布webService

    1. 看看项目结构图 2. cxf的pom依赖 1 <dependency>2 <groupId>org.apache.cxf</groupId>3 <art ...

  5. springboot整合websocket后运行测试类报错:javax.websocket.server.ServerContainer not available

    springboot项目添加websocket依赖后运行测试类报如下错误: org.springframework.beans.factory.BeanCreationException: Error ...

  6. spring-boot整合Cxf的webservice案例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.Maven Plugin管理 <?xml version="1.0&q ...

  7. springboot整合websocket后打包报错:javax.websocket.server.ServerContainer not available

    项目整合了websocket以后,打包多次都没有成功,原来是报错了,报错内容如下: Error starting ApplicationContext. To display the conditio ...

  8. 十六、springboot整合Spring-data-jpa(二)之通用DAO接口与添加自定义方法

    @NoRepositoryBean:Spring Data Jpa在启动时就不会去实例化BaseRepository这个接口 1.通用接口: import org.springframework.da ...

  9. 解决在Filter中读取Request中的流后,后续controller或restful接口中无法获取流的问题

    首先我们来描述一下在开发中遇到的问题,场景如下: 比如我们要拦截所有请求,获取请求中的某个参数,进行相应的逻辑处理:比如我要获取所有请求中的公共参数 token,clientVersion等等:这个时 ...

随机推荐

  1. 《MySQL必知必会》学习笔记——第1章 了解SQL

    第1章 了解SQL 本章将介绍数据库和SQL,它们是学习MySQL的先决条件. 1.1 数据库基础 你正在阅读本书,这表明你需要以某种方式与数据库打交道.在深入学习MySQL及其SQL语言的实现之前, ...

  2. 【Leetcode_easy】893. Groups of Special-Equivalent Strings

    problem 893. Groups of Special-Equivalent Strings 题意: 感觉参考代码也是有点问题的... 参考 1. Leetcode_easy_893. Grou ...

  3. 【Leetcode_easy】925. Long Pressed Name

    problem 925. Long Pressed Name solution1: class Solution { public: bool isLongPressedName(string nam ...

  4. Python3之内建模块collections

    collections是python内建的一个集合模块,提供了许多有用的集合类. namedtuple 我们知道tuple可以表示不可变集合,例如,一个点的二维坐标可以表示成 >>> ...

  5. web端自动化——selenium测试报告生成、找到测试报告路径、实现发邮件(整合)

    有这样的一个场景: 假设生成的测试报告与多人相关,每个人都去测试服务器査看就会比较麻烦,如果把这种主动的且不及时的査看变成被动且及时的査收,就方便多了. 整个程序的执行过程可以分为三个步骤: ①    ...

  6. Input.GetMouseButtonDown 在fixedupdate中会出现丢失问题,在update中则完全没这个问题

    Input.GetMouseButtonDown 在fixedupdate中会出现丢失问题,在update中则完全没这个问题

  7. [OpenCV开发]OpenCV图像编码和解码 imencode和imdecode使用,用于网络传输图片

    在很多应用中,经常会直接把图片的二进制数据进行交换,比如说利用 socket 通信传送图片二进制数据,或者直接用内存数据库(例如 Redis)来传递图片二进制数据. 这个时候,当你的应用程序读到内存里 ...

  8. C#中的System.Web.HttpUtility.UrlEncode转码问题

    最近需要与JAVA程序对接口,其中遇到的URL转码问题: Java中URL编码所用的 URLEncoder.encode 产生的字符是大写且英文'(',')'是分别转成'%28'和 '%29' 而C# ...

  9. Jenkins+maven+gitlab自动化部署之Jenkins部署(三)

    本章开始正式搭建Jenkins: 公司现在使用的jenkins版本是2.150.3,但是本次实验安装的版本我们选择最新的 2.164.3(当然,当你阅读这篇文章时,此版本已经不是最新),jenkins ...

  10. 洛谷P4145——上帝造题的七分钟2 / 花神游历各国

    题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...