【发布时间】:2011-02-16 04:52:24
【问题描述】:
我正在尝试按照本教程:http://www.vogella.de/articles/SpringDependencyInjection/article.html 在我的应用程序中使用注解依赖注入。我在教程中设置了 bean 等,然后尝试在我的 MainController 类中获取 bean 的实例(处理为我的 spring web mvc 应用程序生成特定页面的控制器类).. 我不断得到
SEVERE: Servlet.service() for servlet spring threw exception
java.io.FileNotFoundException: class path resource [WEB-INF/applicationContext.xml] cannot be opened because it does not exist
我在我的 MainController 中这样做:
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
BeanFactory factory = context;
BeanIRPlus beanirPlus = (BeanIRPlus) factory
.getBean("BeanIRPlus");
IRPlusInterface irPlus = beanirPlus.getIRPlus();
我已经对此进行了搜索和搜索,但尚未找到解决我问题的答案。我在 webapp/WEB-INF/ 中的 applicationContext 和我的 spring 应用程序似乎正在工作,因为它在此之前正在处理请求等。我尝试将 applicationContext.xml 放在 WEB-INF 类中,但仍然没有。是否有任何解决方法可以使它不以这种方式搜索路径,因为我认为它在进行相对路径搜索。感谢您的任何建议
【问题讨论】:
标签: spring dependency-injection annotations