Spring MVC中得到Web应用的根路径

 
 
import org.springframework.web.context.ContextLoader;

import javax.servlet.ServletContext;

/**
 * Created by Gong_Yi on 2018/1/26.
 */
public class G {
    String webRootUrl = "/";

    ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
    String webRootPath = servletContext.getRealPath(webRootUrl);
}


猜你喜欢

转载自blog.csdn.net/qq_38844636/article/details/79174816