Spring 引导和解析资源

Spring Boot and Resolving Resources

我有一个新的 Spring 启动应用程序,我想使用包装 bootstrap 模板 在我的 src/main/resources 文件夹中,我有以下文件夹结构 templates/fonts templates/scripts templates/styles

我正在尝试映射这些资源,以便可以使用以下代码在我的 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);
    } 

}

然而,当我寻找像 scripts/home.js 这样的文件时,它没有返回给我,我得到一个 404

任何人都可以提供任何建议,以便我可以正确地获得此映射 运行 吗?

谢谢 达米恩

尝试

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

/编辑:

将您的脚本放入 src/main/resources/static/what/ever.js