1、端口问题
无法访问此网站
网址为 http://localhost:6666/swagger-ui.html 的网页可能暂时无法连接,或者它已永久性地移动到了新网址。
ERR_UNSAFE_PORT 如图:
这是一个很 nt 的东西,你的端口不要搞什么6666,8888之类的,拿8080就好,5678之类的也行,不然浏览器是打不开的
二、swaggerUI 拦截器和跨域冲突处理
如果我们的项目中有关于跨域的处理,同时还有拦截器,然后还要使用swagger,这种情况大家要注意了,有可能我们的拦截器会将swagger中的页面路径拦截掉导致swagger页面出不来,当我们在拦截器中把swagger的页面排除掉的时候,也有可能会导致跨域配置的失效。
拦截器:
package com.example.commonoperation.common.config; import com.example.commonoperation.common.intercepter.TokenInterceptor; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @description: webMvc配置类 * @author: luguilin * @date: 2022-11-04 10:39 **/ @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { //拦截 registry.addInterceptor(new TokenInterceptor()) // 对所有请求进行拦截 .addPathPatterns("/**") // 排除 login请求 .excludePathPatterns("/login") .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**") ; } /** * juejue swagger-ui 404 * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } }
跨域配置:
package com.example.commonoperation.common.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; /** * @description: CorsConfig * @author: luguilin * @date: 2023-01-30 17:08 **/ @Configuration public class CorsConfig { @Bean public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.addAllowedOrigin("*"); config.setAllowCredentials(true); config.addAllowedMethod("*"); config.addAllowedHeader("*"); UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); configSource.registerCorsConfiguration("/**", config); return new CorsFilter(configSource); } }
三、包问题
注意是"." 不是"/"
标签:集成,springboot,springframework,registry,org,import,swagger,config From: https://www.cnblogs.com/r1-12king/p/17076717.html