package com.gkhy.assess.framework.config; import com.gkhy.assess.framework.interceptor.LogInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.io.File; @Configuration public class MyWebMvcConfig implements WebMvcConfigurer { @Value("${image.root_path}") private String uploadRootPath; @Autowired private LogInterceptor logInterceptor; /** * 配置图片访问路径 * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { String systemDir=System.getProperty("user.dir"); registry.addResourceHandler("/api/assess_file/**").addResourceLocations("file:"+systemDir+ File.separator+uploadRootPath+File.separator); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(logInterceptor) .addPathPatterns("/**"); } }