You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring框架Hello World Web应用启动报错:无法打开指定ServletContext资源

Fixing the BeanDefinitionStoreException (File Not Found for applicationConfig.xml)

Hey there! Let's troubleshoot this file not found error you're hitting. That exception makes it clear: Spring can't locate your applicationConfig.xml at the path /web/WEB-INF/applicationConfig.xml. Here's how to resolve this step by step:

1. Verify the Actual File Location

First, double-check your project structure against standard Java Web project conventions:

  • For Maven/Gradle projects, the WEB-INF folder should live directly under src/main/webapp (your web root directory). So the correct path to your config file should be src/main/webapp/WEB-INF/applicationConfig.xml.
  • For non-build-tool projects (like Eclipse Dynamic Web Projects), WEB-INF is under WebContent—so WebContent/WEB-INF/applicationConfig.xml.
  • Make sure you didn't accidentally nest WEB-INF inside an extra /web folder, which is exactly what the error is complaining about.

2. Correct the Spring Configuration Path

If the file is in the right place, the issue is likely in how you're telling Spring where to find it (usually in web.xml):

  • Look for a context-param entry like this:
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/web/WEB-INF/applicationConfig.xml</param-value>
    </context-param>
    
  • Remove the extra /web prefix. The corrected path should be:
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationConfig.xml</param-value>
    </context-param>
    
    Note: ServletContext resources are resolved relative to the web root, so /WEB-INF/... points directly to the file under your web root's WEB-INF folder.

3. Check IDE Deployment Settings

If you're using an IDE (IntelliJ, Eclipse, etc.) to deploy your app:

  • Go to your project's deployment configuration and confirm that your web root directory (e.g., src/main/webapp or WebContent) is correctly mapped to the server's web application root.
  • Ensure that the WEB-INF folder and its contents are marked as part of the deployed resources.

4. Clean and Rebuild Your Project

Sometimes IDE caches or stale build artifacts can cause path mismatches:

  • For Maven projects, run mvn clean install to wipe old builds and generate fresh ones.
  • For Eclipse, use Project > Clean to clear cached files, then re-deploy the app.
  • For IntelliJ, go to File > Invalidate Caches... and restart the IDE, then rebuild the project.

内容的提问来源于stack exchange,提问作者Ladence

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:12:56