spring boot中静态资源配置问题

spring:
  session:
    store-type: HASH_MAP
  cache:
    type: None
  mvc:
    static-path-pattern: /image/**   
  resources:
    static-locations: file:/opt/gray/images

spring boot在本地测试好的在服务器上配置路径访问图片就404了


雨Gemini
浏览 3545回答 1
1回答

慕村4705583

可以考虑在代码中配置。比如:@Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter {     @Override     public void addResourceHandlers(ResourceHandlerRegistry registry) {         registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");         registry.addResourceHandler("/files/**").addResourceLocations("file:///home/community_cloud_admin/upload/images/");         registry.addResourceHandler("/app/**").addResourceLocations("file:///home/community_cloud_admin/upload/package/");      //   registry.addResourceHandler("/app/**").addResourceLocations("file:///D:/community_cloud_admin/upload/package/");         super.addResourceHandlers(registry);     }其中 addResourceHandler 是打开路径  addResourceLocations则是存放路径
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java