SpringMvc+Swagger整合及autowire错误处理

SpringMvc+Swagger的整合及出现的autowire的错误问题

先发下我参考的github的地址
这里先写下错误的解决,具体的整合细节后面再补充


我用的是注解的方式
自定义类的DEMO

@Configuration
@EnableWebMvc
@EnableSwagger
@ComponentScan("com.myapp.controllers")
public class CustomJavaPluginConfig {

   private SpringSwaggerConfig springSwaggerConfig;

   @Autowired
   public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
      this.springSwaggerConfig = springSwaggerConfig;
   }

   @Bean //Don't forget the @Bean annotation
   public SwaggerSpringMvcPlugin customImplementation(){
      return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
            .apiInfo(apiInfo())
            .includePatterns(".*pet.*");
   }

    private ApiInfo apiInfo() {
      ApiInfo apiInfo = new ApiInfo(
              "My Apps API Title",
              "My Apps API Description",
              "My Apps API terms of service",
              "My Apps API Contact Email",
              "My Apps API Licence Type",
              "My Apps API License URL"
        );
      return apiInfo;
    }
}

这里要注意
1.@EnableWebMvc这个要有,我百度上好多的文章都没有这个注解
2.我的spring-mvc.xml里面的配置是没有
<bean class="com.xxx.xxx.CustomJavaPluginConfig"/>
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
的配置项
3.有的文章说去掉@Configuration然后xml里面配置上
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />,这样是可以跑通,这时会生成一个默认的Config类,你自己自定义的CustomJavaPluginConfig这个类就没有用了

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值