参考版本

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. Top 10 Machine Learning Algorithms For Beginners

    Linear Regression Logistic regression KNN Classification Support Vector Machine (SVM) Decision Trees ...

  2. 《第一本Docker书》学习笔记——第3章 Docker入门

    3.1 确保Docker已经就绪 查看docker是否正常工作: sudo docker info 3.2 运行我们的第一个容器 现在,让我们尝试启动第一个Docker容器.我们可以使用docker ...

  3. 对 Watchbog Botnet 渗透过程和 Payload 的分析

    漏洞利用 CVE-2018-1000861 https://jenkins.io/security/advisory/2018-12-05/ Watchbog在做什么? Watchbog僵尸网络为其所 ...

  4. C# sqlsugar依赖引用报错的问题解决

    English Message : You need to refer to MySql.Data.dll↵Chinese Message : 需要引用MySql.Data.dll,请在Nuget安装 ...

  5. 用anaconda保证64位和32位的python共存

    conda info # 查看当前工作平台 set CONDA_FORCE_32BIT=1 # 切换到32位 set CONDA_FORCE_32BIT=0 # 切换到64位 conda create ...

  6. 【VS开发】最小化到托盘 shell_notifyicon和NOTIFYICONDATA

    shell_notifyicon和NOTIFYICONDATA Shell_NotifyIcon函数,向任务栏的状态栏发送一个消息 函数原型 BOOL Shell_NotifIcon( DWORD d ...

  7. git push时出现大文件的处理方法

    最近在提交项目时出现报错 文件限制只能100M,但是里面有个文件202M,超过了码云的限制. 所以顺手就把这个文件删除了 然后发现还是同样的报错,反复检查目录还是不行,找了资料说,需要git rm 命 ...

  8. JVM(二) 栈内存结构

    栈内存是描述java方法执行的内存模型,每个方法在执行的同时都会创建一个栈帧(Stack Frame)用于存储局部变量表.操作数栈.动态链接.返回出口等信息.每一个方法从调用直至执行完成的过程,就对应 ...

  9. C++大数运算模板

    #include<iostream> #include<cstring> #include<cstdio> #include<iomanip> #inc ...

  10. Valgrind工具------可以分析内存泄漏

    Valgrind 是个开源的工具,功能很多.例如检查内存泄漏工具---memcheck. 安装: 1)官网下载:http://www.valgrind.org/downloads/ , 下载tar.b ...