Spring Maven - 资源文件夹中的上下文配置

时间:2013-05-14 18:39:11

标签: java spring maven servlets jetty

正如我在stackoverflow的其他问题中发现的那样,最好将spring的配置保存在src / main / resources文件夹中。但是,当我使用mvn jetty时:运行它尝试从WEB-INF加载上下文配置,无论我在web.xml中输入什么。我收到以下错误:

javax.servlet.ServletException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/easyscrum-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/easyscrum-servlet.xml]

如何强制servlet从classpath而不是web-inf加载配置?

1 个答案:

答案 0 :(得分:3)

要从类路径加载spring配置上下文文件,您必须在路径前加classpath:

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