解决方案 »

  1.   

    如果由web.xml来管理配置文件,你就不需要用FileSystemXmlApplicationContext来获取xml文件,你需要拿到哪个bean直接@Resource就OK了
      

  2.   

    真接可以用annotation的方式去获取对吧!
      

  3.   

    可以在web.xml中定义一个ServletContextListener,在里面获取当前tomcat中的项目的真实路径,将这个路径存到一个全局静态变量里面,这样你就可以随时获取tomcat的路径了。
    部分代码如下:public class ComtextListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent sce) {
    } public void contextInitialized(ServletContextEvent sce) {
    Constants.appRoot = sce.getServletContext().getRealPath("/");//格式:D:/tomcat/Project_Name
    }
    }