1. 程式人生 > >Springboot 2.x 外部資原始檔配置

Springboot 2.x 外部資原始檔配置

springboot1.5的寫法過時,2.x版本寫法如下

@Configuration
//@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

	@Value("${file.staticAccessPath}")
	private String staticAccessPath;
	@Value("${file.uploadFolder}")
	private String uploadFolder;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
		//registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
	}

}