此配置是处理springboot拦截静态文件的

代码:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 添加静态资源文件,外部可以直接访问地址
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //如下配置则能可以访问src/main/resources/static下面的文件
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}

 

相关文章:

  • 2022-01-02
  • 2021-11-30
  • 2021-11-20
  • 2021-12-10
  • 2021-09-26
  • 2021-11-25
  • 2021-10-21
猜你喜欢
  • 2022-12-23
  • 2021-05-03
  • 2021-11-20
  • 2021-03-31
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案