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等等:这个时 ...
随机推荐
- 使用postman调用webservice接口
通过wsdl查看接口地址: 填入xml报文: 配置相应的headers:
- 【mysql】reset Password
https://www.cnblogs.com/josn1984/p/8550419.html https://blog.csdn.net/l1028386804/article/details/92 ...
- (十三)class文件结构:常量池(转)
Class类文件的结构 全局规范 1.任何一个Class文件都对应着唯一一个类或接口的定义信息,但反过来说,类或接口并不一定都得定义在文件里(譬如类或接口也可以通过类加载器直接生成).本章中,只是通俗 ...
- 03点睛Spring4.1-scope
转载:https://www.iteye.com/blog/wiselyman-2210377 3.1 scope scope描述spring容器是怎么样新建类的实例的(bean); 在spring中 ...
- 开发环境下的 Kubernetes 容器网络演进之路
马蜂窝技术原创文章,更多干货请搜索公众号:mfwtech 使用 Docker+Kubernetes 来简化开发人员的工作流,使应用更加快速地迭代,缩短发布周期,在很多研发团队中已经是常见的做法. 如果 ...
- CF1239A Ivan the Fool and the Probability Theory
思路: 可以转化为“strip”(http://tech-queries.blogspot.com/2011/07/fit-12-dominos-in-2n-strip.html)问题.参考了http ...
- rsync同步本地和服务器之间的文件
同步本地文件到服务器 rsync -zvrtopg --progress --delete test -e 'ssh -p 6665' yueyao@172.16.0.99:/media/sdb/us ...
- e.g. i.e. etc. et al. w.r.t. i.i.d.英文论文中的缩写语
e.g. i.e. etc. et al. w.r.t. i.i.d. 用法:, e.g., || , i.e., || , etc. || et al., || w.r.t. || i.i.d. e ...
- java生成验证码结合springMVC
在用户登录的时候,为了防止机器人攻击都会设置输入验证码,本篇文章就是介绍java如何生成验证码并使用在springMVC项目中的. 第一步:引入生成图片验证码的工具类 import java.awt. ...
- Scala 算法案例
移除第一个负数之后的所有负数 // 构建数组 val a = ArrayBuffer[Int]() a += (1, 2, 3, 4, 5, -1, -3, -5, -9) // 每发现一个第一个负数 ...