Springboot整合Swagger过程中遇到的坑

       Springboot整合swagger的步骤以及出现问题的解决
第一步:引入swagger的依赖文件:
<dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger2</artifactId>
         <version>2.7.0</version>
  </dependency>
<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
</dependency> 这里的版本为2.7.0。

第二步:写配置文件,纯Java配置。

@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xxx.demo.web"))//扫描的是自己写Controller的包名。
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")//swagger的title
                .description("简单优雅的restfun风格")//自己定义
                .termsOfServiceUrl("http://blog.csdn.net/")//自己定义
                .version("1.0")
                .build();
    }

       这样的话,当自己启动Springboot启动类,然后按照当初自己给的端口(如果自己在配置文件里面配置了访问的时候必须加项目名称,哪自己的记住!)例如我访问的就是:http://localhost:8080/swagger-ui.html。这样就可以看到自己定义的接口了。但如果自己要写测试类测试自己写的接口,按照这种方式配置的swagger,在进行单元测试的时候会报错误。如下:

org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$cfbcb6cb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-05-16 11:58:07.671 WARN 11268 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值