java - Spring Boot 和解析资源

标签 java spring spring-boot bootstrapping

我有一个新的 Spring Boot 应用程序,我想使用包装引导模板 在我的 src/main/resources 文件夹中,我有以下文件夹结构 模板/字体 模板/脚本 模板/样式

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

}

但是,当我查找像 script/home.js 这样的文件时 - 它没有返回给我,我得到了 404

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

谢谢 达米安

最佳答案

尝试

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

/编辑:

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

关于java - Spring Boot 和解析资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639206/

相关文章:

java - 无法使用 JavaFX 将网格居中

java - 如何定义析构函数?

java - 在 Netbeans 中生成 WSDL 时出错

java - 正确使用java Commons BeanUtils?

java - 查询返回多条记录

spring-boot - 如何在 Spring Boot 中禁用 jndi 调试日志

java - 如何取消引用使用 intelliJ-IDE 构建的 Spring MVC 应用程序的旧 Wildfly 9.0.1 部署 Artifact ?

java - 通过预授权保护 vaadin 8 View (Spring Security)

java - 在gradle中导入Apache速度会降级HttpServletResponse

java - zipkin 不显示日志