我在web.xml文件中配置了一个servlet在项目启动时启动这个servlet配置如下
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>com.res.test.Test</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
servlet内容如下:
public void init() throws ServletException {
// Put your code here
System.out.println("进入了!");
ApplicationContext oAC = new FileSystemXmlApplicationContext("/WEB-INF/applicationContext.xml");
Gx=(IManager)oAC .getBean("gxCtrlMng");
new Ts().start();
}
启动tomcat以后就报找不到这个文件的错误,我应该怎么写才能找到applicationContext.xml这个文件呢,谢谢了
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:\Tomcat5.5\bin\WEB-INF\applicationContext.xml]; nested exception is java.io.FileNotFoundException: WEB-INF\applicationContext.xml (系统找不到指定的路径。)
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>com.res.test.Test</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
servlet内容如下:
public void init() throws ServletException {
// Put your code here
System.out.println("进入了!");
ApplicationContext oAC = new FileSystemXmlApplicationContext("/WEB-INF/applicationContext.xml");
Gx=(IManager)oAC .getBean("gxCtrlMng");
new Ts().start();
}
启动tomcat以后就报找不到这个文件的错误,我应该怎么写才能找到applicationContext.xml这个文件呢,谢谢了
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:\Tomcat5.5\bin\WEB-INF\applicationContext.xml]; nested exception is java.io.FileNotFoundException: WEB-INF\applicationContext.xml (系统找不到指定的路径。)
"/applicationContext.xml"
还是把tomcat路径加上了啊,我的项目 是放在D:盘下的在tomcat的C:\Tomcat5.5\conf\Catalina\localhost中配置了一个启动文件,大家帮帮忙了谁会啊。
是这个路径
不是C:\Tomcat5.5\bin\applicationContext.xml
异常信息不是写的很清楚了么。。
<Context docBase="D:\lk\CODE" path="/bjcert" crossContext="true" reloadable="false"/>
所以tomcat下面没有C:\Tomcat5.5\bin\WEB-INF\applicationContext.xml 这个啊
老大你使用FileSystemXmlApplicationContext你就得写完全路径啊(硬盘上的完全路径)
否则的话你使用ClassPathXmlApplicationContext这个类获得application对象。
首先在web.xml中配置
<servlet>
<servlet-name>Dispatchermy</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
然后在servlet中init()方法中
ServletContext ctx=getServletContext();
Gx=(IManager)WebApplicationContextUtils.getWebApplicationContext(ctx).getBean("gxCtrlMng");
就可以了