SpringMVC 集成 Swagger【问题】 No qualifying bean of type RequestMappingHandlerMapping found for depende...

问题描述

近期了解了swagger,通过swagger进行可视化的编辑和定义UI。
Swagger可以帮助开发者简单的管理REST风格的API,并且支持多种框架下的管理

本文主要介绍通过SpringMVC进行集成Swagger的经历
采用的是SpringFox的开源实现,组件可以自动扫描spring的controller, 并且自动生成查询接口目录
如果引入tomcat的话,可以自动开放http://[ip]:[port]/[servicename]/[api-docs]的rest接口

通过swagger-ui可以生成漂亮的界面

中文介绍参见:酸嘢的博客
参考博客: 刘新宇的博客
集成参考

  1. SpringMVC项目接入Springfox
  2. Swagger框架学习分享

集成中遇到的坑

  1. jar包引入,通过maven管理的话:pom文件应该增加
<!--springfox依赖-->
<dependency>
    <groupId>com.mangofactory</groupId>
    <artifactId>swagger-springmvc</artifactId>
    <version>1.0.2</version>
</dependency>
<!--jackson依赖-->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.2</version>
</dependency>
<!--静态页面依赖的webjar-->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>swagger-ui</artifactId>
    <version>2.1.8-M1</version>
</dependency>
  1. 配置方式冲突问题,错误日志显示的模棱两可,问题描述如下

    No qualifying bean of type [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] found for dependency

经过网上调查结果, 发现是配置冲突的问题

上述文章中配置方式都是全部注解的,也许没有什么大问题
但是世界项目中是注解和xml文件配置都有,所以可能产生冲突
查看了下面的两个问题回复
[stringfox issue 462],[stringfox issue 160]

I was having the same problem and am using the XML configuration.
I removed the @Configuration attribute from my SwaggerConfig and it worked fine.

最终看到了,按照SpringMVC项目接入Springfox进行集成的话
如果出现了上述问题,将@Configuration配置干掉,而是采用bean的方式进行配置

问题集合
[stringfox issue 462]: https://github.com/springfox/springfox/issues/462
[stringfox issue 160]: https://github.com/springfox/springfox/issues/160
[竞态条件深入分析]: http://forum.spring.io/forum/spring-projects/web/112154-unable-to-autowire-requestmappinghandlermapping-in-controller

转载于:https://www.cnblogs.com/driftsky/p/4952918.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值