springmvc静态资源配置多个资源路径,按照配置的路径顺序加载访问对应的静态资源

tech2025-01-15  6

springmvc静态资源配置多个location路径,使用逗号隔开 示例: 优先加载文件夹中的assets目录下的资源,如果找不到再到classpath中找

xml配置 <mvc:resources location="/assets/,classpath:/assets/" mapping="/assets/**" /> springboot配置 @Configuration public class FrontWebMvcConfiguration implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/assets/**") .addResourceLocations(new String[]{"/assets/","classpath:/assets/"}); } }
最新回复(0)