我是靠谱客的博主 大胆猎豹,这篇文章主要介绍SpringBoot使用webjars处理静态资源,现在分享给大家,希望可以做个参考。

配置方法

  1. 打开WebJars - Web Libraries in Jars,找到jquery,
  2. 导入依赖
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>3.6.0</version>
    </dependency>

     3. 在resources文件夹下,建立static,public,resources文件夹,其中3个文件夹的文件访问优先级为,resources>public>static。

public void addResourceHandlers(ResourceHandlerRegistry registry) {
          if (!this.resourceProperties.isAddMappings()) {
                logger.debug("Default resource handling disabled");
          } else {
                this.addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/");
                this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> {
                    registration.addResourceLocations(this.resourceProperties.getStaticLocations());
                    if (this.servletContext != null) {
                        ServletContextResource resource = new ServletContextResource(this.servletContext, "/");
                        registration.addResourceLocations(new Resource[]{resource});
                    }

                });
          }
 }

根据代码,如果在properties文件中建立了映射,则不会自动访问resources的文件夹。

最后

以上就是大胆猎豹最近收集整理的关于SpringBoot使用webjars处理静态资源的全部内容,更多相关SpringBoot使用webjars处理静态资源内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(140)

评论列表共有 0 条评论

立即
投稿
返回
顶部