Spring - 加载applicationContext.xml的问题

时间:2016-09-01 12:06:12

标签: java eclipse spring spring-mvc

当尝试在Tomcat上运行项目时,我得到:

public class MyServiceTask implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        // Do something to get the data for your variable
        Object value = ...;

        // Set the variable
        execution.setVariable("VARNAME", value);
    }
}

的web.xml:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

我的applicationContext.xml文件位于src / main / java / applicationContext.xml。

src / main / java在我的Eclipse项目的构建路径中被配置为源文件夹,所以我不明白为什么Tomcat没有找到applicationContext.xml?

2 个答案:

答案 0 :(得分:1)

尝试将其放在WEB-INF目录下,并在下面进行

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

答案 1 :(得分:0)

您应该提供上下文文件的正确路径,如下所示 <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/classes/applicationContext.xml</param-value> </context-param>

当BeanFactory遇到无效的bean定义时抛出BeanDefinitionStoreException:例如如果bean元数据不完整或相互矛盾。

参考:http://docs.spring.io/autorepo/docs/spring-framework/3.2.17.RELEASE/javadoc-api/org/springframework/beans/factory/BeanDefinitionStoreException.html