我用的是注解的方式
自定义类的DEMOspring
@Configuration
@EnableSwagger
@EnableWebMvc
public class SwaggerConfig
{api
public SpringSwaggerConfig springSwaggerConfig;spring-mvc
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}mvc
@Bean
public SwaggerSpringMvcPlugin customImplementation(){
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.apiInfo(new ApiInfo("api", "desc", null, null, null, null))
.useDefaultResponseMessages(false)
.includePatterns("/app.*");
}
}app
这里要注意
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这个类就没有用了this