swagger-ui 访问不到404 No mapping for GET /swagger-ui.html

之前由于springboot 集成shiro ,然后开放了cookie 导致 跨域问题,然后为了解决跨域问题 继承了WebMvcConfigurationSupport ,然后导致 swagger-ui 访问出现404异常!

解决方案由下: 将之前集成的 WebMvcConfigurationSupport 更改为 实现 WebMvcConfigurer 即可!

 源码由下:


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    //解决swagger 问题
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**");
    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }

   //解决cors 跨域问题
    public void addCorsMappings(CorsRegistry registry) {
        //设置允许跨域的路径
        registry.addMapping("/**")
                //设置允许跨域请求的域名
                //   .allowedOrigins("*")
                .allowedOriginPatterns("*")
                //这里:是否允许证书 不再默认开启
                .allowCredentials(true)
                //设置允许的方法
                .allowedMethods("*")
                //跨域允许时间
                .maxAge(3600);
    }
}

配置完成之后 重启服务即可 解决!!

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您在访问`/swagger-ui.html`时出现了`No mapping for GET`错误。这个错误通常是由于您的应用程序缺少相应的请求映射所引起的。 要解决这个问题,您可以尝试以下几个步骤: 1. 确保您的应用程序中已经正确配置了Swagger相关的依赖项。您可以在`pom.xml`文件中添加以下依赖项: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> ``` 或者,如果您使用Gradle构建工具,则可以在`build.gradle`文件中添加以下依赖项: ```groovy implementation 'io.springfox:springfox-swagger2:2.9.2' implementation 'io.springfox:springfox-swagger-ui:2.9.2' ``` 2. 确保您的应用程序中已经正确配置了Swagger的相关配置类。您可以创建一个继承自`WebMvcConfigurationSupport`的配置类,并重写`addResourceHandlers`方法,将Swagger的资源路径添加到资源处理程序中。例如: ```java @Configuration @EnableSwagger2 public class SwaggerConfig extends WebMvcConfigurationSupport { @Override protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } } ``` 3. 确保您的应用程序中已经正确配置了Swagger的API文档。您可以创建一个Swagger配置类,并使用`@Api`和`@ApiOperation`等注解来定义API接口和操作。例如: ```java @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build(); } } ``` 请根据您的具体情况检查以上步骤,并确保正确配置了Swagger相关的依赖项、配置类和API文档。如果问题仍然存在,请提供更多详细信息以便我能够更好地帮助您解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值