在这里插入代码片引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
在config中写入页面
SwaggerConfig页面中写入内容
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static void main(String[] args) {
SpringApplication.run(SwaggerConfig.class, args);
}
}
swagger2在security验证时书写格式为:
@Override
public void configure(WebSecurity web) throws Exception {
//allow Swagger URL to be accessed without authentication
web.ignoring().antMatchers("/v2/api-docs", //swagger api json
"/swagger-resources/configuration/ui", //用来获取支持的动作
"/swagger-resources", //用来获取api-docs的URI
"/swagger-resources/**", //安全选项
"/webjars/springfox-swagger-ui/**", //确保有样式
"/swagger-ui.html")
;
}