Spring加载dispatcher-servlet.xml失败,请求排查FileNotFoundException问题
Hey there, let's tackle this frustrating issue you're hitting. That BeanDefinitionStoreException is just a wrapper—the real problem is Spring can't find your /web-inf/dispatcher-servlet.xml file (the nested FileNotFoundException gives that away). Let's go through the most common causes and fixes step by step:
Common Causes & Solutions
1. Case Sensitivity in Path (Super Common!)
Most Servlet containers (like Tomcat) are case-sensitive when it comes to resource paths. Notice your error says /web-inf/—but the standard directory name is WEB-INF (all uppercase).
- Fix: Double-check two things:
- The path in your
web.xmluses/WEB-INF/dispatcher-servlet.xml(not lowercaseweb-inf). - The actual file is stored in your project's
WEB-INFdirectory (not a lowercaseweb-inffolder you accidentally created).
- The path in your
2. File is in the Wrong Directory
Spring looks exactly where you tell it to. If your dispatcher-servlet.xml is tucked inside a subfolder like WEB-INF/config/ instead of the root WEB-INF directory, the path /WEB-INF/dispatcher-servlet.xml won't find it.
- Fix:
- Either move the file directly into the
WEB-INFroot, or - Update the path in
web.xmlto match its actual location (e.g.,/WEB-INF/config/dispatcher-servlet.xml).
- Either move the file directly into the
3. Misconfigured web.xml
Let's verify your DispatcherServlet setup in web.xml—this is where the path is usually defined. A correct setup looks like this:
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
- Checks:
- Make sure the
param-valuematches the exact path and filename of your XML file (no typos!). - If you didn't specify
contextConfigLocation, Spring defaults to/WEB-INF/[servlet-name]-servlet.xml. So if your servlet name isdispatcher, it expectsdispatcher-servlet.xml—confirm your filename matches that.
- Make sure the
4. Project Packaging/Deployment Issue
If you're using a build tool like Maven or Gradle:
- Ensure
dispatcher-servlet.xmlis in thesrc/main/webapp/WEB-INFdirectory of your project. Files here get packaged into theWEB-INFfolder of your WAR file automatically. - If you put the file in
src/main/resourcesinstead, it ends up in the classpath, not the ServletContext. In that case, you need to update the path to useclasspath:dispatcher-servlet.xmlinstead of/WEB-INF/....
Quick Debug Tip
If you're still stuck, build your WAR file and unzip it to check if dispatcher-servlet.xml is present in the WEB-INF folder. That will confirm if the issue is with packaging or path configuration.
内容的提问来源于stack exchange,提问作者Raspberry

