第三个参数locations表示为地址集合(classpath:/META-INF/resources/webjars/),我们试试访问该地址下的bower.json看看是否可以访问,地址对应路径为下面红框框部分: 这里我们只需要在路径后面加上/webjars/jquery/3.6.0/bower.json,就可以访问到该文件。 (注意:#spring.web.resources.add-mappings=false一定要注释掉,...
在配置文件中配置spring.web.resources.add-mappings=true,默认是true,这在下面代码中判断该属性,如果配置成false 所有静态资源配置都清空,就是禁用静态资源访问 @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug("Default re...
spring.resources.add-mappings=true # Enable default resource handling. spring.resources.cache-period= # Cache period for the resources served by the resource handler, in seconds. spring.resources.chain.cache=true # Enable caching in the Resource chain. spring.resources.chain.enabled= # Enable the ...
可以使用spring.web.resources.static-locations: 进行更改指定的静态资源文件夹 @ConfigurationProperties("spring.web") public class WebProperties { public static class Resources { private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", ...
1)、所有 /webjars/** ,都去 classpath:/META-INF/resources/webjars/ 找资源;== webjars:以jar包的方式引入静态资源; 2)、"/**" 访问当前项目的任何资源,都去(静态资源的文件夹)找映射 "classpath:/META-INF/resources/", "classpath:/resources/", ...
/*** Path pattern used for static resources.*/private String staticPathPattern = "/**"; 第二步,如果资源请求没有对应映射,就添加资源处理器及资源找寻位置并设置缓存 if (!registry.hasMappingForPattern(staticPathPattern)) {customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern)....
if(!registry.hasMappingForPattern("/webjars/**")) { this.customizeResourceHandlerRegistration( //都去 classpath:/META-INF/resources/webjars/ 找资源 registry.addResourceHandler(newString[]{"/webjars/**"}). addResourceLocations( newString[]{"classpath:/META-INF/resources/webjars/"}).setCache...
resources: static-locations: [classpath:/my/] 访问http://localhost:8888/my.txt,也成功了。 最后,把静态资源开关关掉。 spring: profiles: test resources: static-locations: [classpath:/my/] add-mappings: false 这样就访问不到任何静态资源了,不过一般来说不用关。
# spring.resources.add-mappings=false 为什么404需要额外处理? 下面尽量以通俗易懂的方式说明下这个问题 java web应用,除了返回json类数据之外还可能返回网页,js,css 我们通过@ResponseBody来表明一个url返回的是json数据(通常情况下是这样的,不考虑自定义实现) ...
就是去类路径下找到/META-INF/resources/webjars/下的文件, 例子: 访问http://localhost:8080/webjars/jquery/3.6.0/jquery.js 实测成功 总结: SpringBoot处理静态资源的方式 webjars:http://localhost:8080/webjars/jquery/3.6.0/jquery.js pubilc:按优先级排序:resources,static,public,如何访问:/**: ...