gpt4 book ai didi

java - spring boot war 中来自 ${catalina.home} 的静态资源

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:45 24 4
gpt4 key购买 nike

在我的 Spring MVC 项目中我有

<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/, file:${catalina.home}/myresources/" />

配置为从多个位置提供静态资源。然而,在 Spring Boot 中,

@Configuration
public class ResourceConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/", "file:${catalina.home}/myresources/");
}
}

未按预期工作。请帮忙。

最佳答案

    @Configuration
public class ResourceConfig implements WebMvcConfigurer {

private static final Log LOG = LogFactory.getLog(ResourceConfig.class);

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
String catalinaHome;
try {
catalinaHome = System.getenv("CATALINA_HOME");
} catch (Exception e) {
LOG.error(e);
catalinaHome = "";
}
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/", "file:" + catalinaHome + "/myresources/");
}
}

关于java - spring boot war 中来自 ${catalina.home} 的静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54140274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com