注册 X
我已阅读并同意  服务条款
首页 > IT技术笔记 > 查看笔记

springboot配置虚拟目录

在springboot启动类同级下增加ApplicationConfig.java

点击复制

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 配置虚拟目录
 * @author jspanjsp
 *
 */

@Configuration
public class ApplicationConfig extends WebMvcConfigurerAdapter {
	
	private String "D:/upload/";
	
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*
        * 说明:增加虚拟路径(经过本人测试:在此处配置的虚拟路径,用springboot内置的tomcat时有效,
        * 用外部的tomcat也有效
        */
        //Windows下
        registry.addResourceHandler("/upload/**").addResourceLocations("file:"+dic);
        super.addResourceHandlers(registry);
    }
}			
		

 打赏        分享



评论