当前位置: 代码迷 >> Web前端 >> 用spring resource 接口获取 web使用的ROOT目录
  详细解决方案

用spring resource 接口获取 web使用的ROOT目录

热度:234   发布时间:2012-08-28 12:37:01.0
用spring resource 接口获取 web应用的ROOT目录
Resource r = new ClassPathResource("log4j.properties");
			File f = r.getFile().getParentFile().getParentFile()
					.getParentFile();
String path = f.getAbsolutePath() + File.separator + "sitemap.xml";
1 楼 huhang1986 2011-05-12  
我觉得让bean实现ServletContextAware接口
通过servletContext获得web根目录更自然。

不知道我跟你说的是不是一个目录~~
2 楼 wutao8818 2011-05-23  
我这个不是用在 spring bean 里面的, 是个工具类的 static 方法,纯粹是为了任何地方都可以调用方便一些, 当然你说的方法也是可以的。看你用的地方了。
  相关解决方案