springboot整合security,swagger2页面

该博客介绍了如何在SpringBoot应用中集成Swagger2,通过引入相关依赖并配置SwaggerConfig,实现API的文档化和免认证访问。配置包括Swagger2和Swagger-UI的依赖引入,以及WebSecurity的设置,允许未授权访问Swagger相关URL。
摘要由CSDN通过智能技术生成

在这里插入代码片引入依赖

		<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")     
        ;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值