首页 > 代码库 > BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource

BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource

Tomcat报错如下:

BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource

 

错误原因:

Tomcat在解析xml时,找不到相应的资源.

解决方法:

如果applicationContext.xml放在src文件下面,则在web.xml中加上:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

如果applicationContext.xml放在WEB-INF下面,则在web.xml中加上

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
< /context-param>

 此外,如果在类中通过ClassPathXmlApplicationContext获取context,则必须把applicationContext.xml直接放在src文件下。

ApplicationContext context= new ClassPathXmlApplicationContext("applicationContext.xml");

如果applicationContext.xml放在其他路径下,可以用FileSystemXmlApplicationContext通过绝对路径实例化context.

BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource