- pom 文件 在 maven 仓库中输入 springfox查到最新的
<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.配置
主要映射 视图
不然访问不了
访问地址
localhost:9000/swagger-ui.html
@Configuration
public class WebMVCConfig extends WebMvcConfigurerAdapter {
/**
* 配置swagger 映射路径
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
开启,填写相关信息
@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan(basePackages = { "cn.lucode.*" })
public class SwaggerConfig {
ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("lucode Web SelfService APIs")
.description("")
.license("")
.licenseUrl("")
.termsOfServiceUrl("")
.version("1.0.0")
.build();
}
@Bean
public Docket customImplementation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("cn.lucode"))
.build()
.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
.apiInfo(apiInfo());
}
}
相关的方法和类的注解,参考
http://blog.csdn.net/u014231523/article/details/76522486
http://www.jianshu.com/p/12f4394462d5