您的位置:首页 > 编程语言 > Java开发

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这个类就没有用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring mvc swagger