SpringMvc+Swagger整合及autowire错误处理
2016-11-29 10:47
405 查看
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" ); < 4000 span class="hljs-keyword">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这个类就没有用了
相关文章推荐
- SpringMvc+Swagger整合springSwaggerConfig 无法注入错误处理
- 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例
- 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例
- SpringMVC @ResponseBody 415错误处理
- springMvc+swagger整合例子
- SpringMVC @ResponseBody 415错误处理
- Spring + Spring MVC + Mybatis + Swagger + javaConfig 整合项目 全注解方式
- SpringMVC @ResponseBody 415错误处理
- Spring MVC +Spring +mybatis 整合事务处理
- Spring boot+Shiro+ spring MVC+swagger UI +Mybatis+mysql+Vue +Element UI 之四 vue 整合Element UI
- spring-mvc整合freemarker并在ftl模版中显示服务端校验的错误信息,JSR303或者JSR349
- SpringMVC @ResponseBody 415错误处理
- Swagger+Spring+Spring Mvc项目整合DEMO
- SpringMVC+Swagger详细整合
- swagger+springmvc接口在线文档完美整合
- SpringMVC @ResponseBody 415错误处理
- Spring boot+Shiro+ spring MVC+swagger UI +Mybatis+mysql+Vue +Element UI 之一vue和spring boot整合
- springMvc+swagger整合例子
- Swagger SpringMVC整合与简介
- SPRINGMVC+SWAGGER整合例子