- 使用下面的代码
ServletContext
在SpringMVC中自动连接对象
@AutowiredServletContext context;
然后尝试执行您的代码
String uploadPath = context.getRealPath("") + File.separator + UPLOAD_DIRECTORY;- 您可以像这样在控制器中获取它;
private ServletContext context;public void setServletContext(ServletContext servletContext) {this.context = servletContext;}但是为此,您的控制器必须实现
ServletContextAware接口



