1、页面

<!DOCTYPE html> <html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>账号授权失败</title> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <link rel="stylesheet" type="text/css" th:href="@{/h5/static/style/style.css}"> </head> <body> <div class="auth" style="text-align: center;margin-top: 40%"> <p class="fail-icon"></p> <h5>账号授权失败</h5> <h6 th:text="${errorMsg}"></h6> </div> </body> </html>
请注意:<link rel="stylesheet" type="text/css" th:href="{/h5/static/style/style.css}">
2、java代码

package com.softcore.msoft.h5.client.config; import com.softcore.msoft.core.interceptor.AppSignInterceptor; import com.softcore.msoft.core.interceptor.DebugInterceptor; import com.softcore.msoft.core.interceptor.FansInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.util.ResourceUtils; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author gaowang * @createTime 2020/11/11 17:14 */ @Configuration public class WebConfig implements WebMvcConfigurer { @Autowired private DebugInterceptor debugInterceptor; // @Autowired // private FansInterceptor fansInterceptor; /** * 拦截器注册 * * @param registry */ @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(debugInterceptor).addPathPatterns("/**"); } /** * 跨域访问支持 * * @param registry */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedOrigins("*").allowCredentials(true).allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH").maxAge(3600); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/h5/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/"); } }
这句话起到路径映射:registry.addResourceHandler("/h5/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/");
3、zuul配置
zuul.routes.h5-client.path=/h5/** zuul.routes.h5-client.strip-prefix=false zuul.routes.h5-client.serviceId=msoft-h5-client
如此可以解决zuul转发静态资源访问问题并支持分布式服务