简体   繁体   English

Spring Boot和解决资源

[英]Spring Boot and Resolving Resources

I have a new Spring Boot app and I would like to use a wrap bootstrap template In my src/main/resources folder I have the following folder structure templates/fonts templates/scripts templates/styles 我有一个新的Spring Boot应用程序,我想使用wrap bootstrap模板。在我的src / main / resources文件夹中,我有以下文件夹结构模板/字体模板/脚本模板/样式

I am trying to map these resources so they can be picked up in my html code using the following code 我正在尝试映射这些资源,以便可以使用以下代码在我的html代码中进行选择

   @Configuration

public class MvcConfiguration extends WebMvcConfigurerAdapter{


    private static final String templateFolder = "/templates/slim/client";
    private static final String localCSSFolder = "/templates/slim/.tmp";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        LOG.info("Entered addResourceHandlers");

        registry.addResourceHandler("/fonts/**").addResourceLocations("templates/fonts/**");
        registry.addResourceHandler("/scripts/**").addResourceLocations("templates/scripts/**");
        registry.addResourceHandler("/styles/**").addResourceLocations("templates/styles/**");

        super.addResourceHandlers(registry);
    } 

}

However when I look for a file like scripts/home.js - it is not being returned to me and I get a 404 但是,当我寻找像scripts / home.js这样的文件时,它没有返回给我,并且得到404

Can anyone offer any advise so I can get this mapping running correctly? 谁能提供任何建议,以便我可以正确运行此映射?

Thank you Damien 谢谢达米恩

Try 尝试

    registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");

/Edit: /编辑:

Put your scripts in src/main/resources/static/what/ever.js 将您的脚本放在src / main / resources / static / what / ever.js中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM