72889

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser

Question:

When I launch my application I get this error

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml] nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-servlet.xml]

Meanwhile, I dont have any file like SpringDispatcher-servlet.xml neither do I in my web.xml or mvc-dispatcher-servlet.xml file defined in my WEB-INF folder.

<strong>web.xml file</strong>

<context-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>SpringDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SpringDispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </context-param> <session-config> <session-timeout>30</session-timeout> </session-config>

<strong>mvc-dispatcher-servlet.xml file</strong>

<context:component-scan base-package="aish.vaishno.musicstore.controller" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/" /> <property name="suffix" value=".jsp" /> </bean>

Please how can I locate this file

/WEB-INF/SpringDispatcher-servlet.xml

Please what am I getting wrong?

Answer1:

Spring is looking SpringDispatcher-servlet.xml in your web project and as it is unable to find it, it is throwing an exception.

You can override the dispatcher servlet xml file like this - providing blank arguments.

<servlet> <servlet-name>SpringDispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value> </init-param> </servlet>

Answer2:

When you define Dispatcher servlet in web.xml spring expects Web application context name as Disptacherservletname-servlet.xml under /WEB-INF/ . In your case it should be SpringDispatcher-servlet.xml not mvc-dispatcher-servlet.xml

Or you can use contextConfigLocation parameter to follow your own naming conventions.

<servlet> <servlet-name>SpringDispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> </init-param> </servlet>

Answer3:

In your web.xml you have define the servlet to be

<servlet> <servlet-name>SpringDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet>

therefore, you nee to create a file named <strong>SpringDispatcher-servlet.xml</strong> inside your <strong>WEB-INF</strong> folder. This is just how it works. If you change the servlet-name to be dispatcher then the file name should be dispatcher-servlet.xml. Your SpringDispatcher-servlet.xml contains the definitions of your spring context. Take a look on this <a href="https://javapointers.com/tutorial/create-spring-mvc-project-using-maven/" rel="nofollow">tutorial</a>.

Recommend

  • Naming Database Tables and Views
  • Trying to implement inline Webworker for a recursive function
  • Handling Surrogate pairs while parsing xml using libxml2
  • Unknown Error on Web Host but code runs well on localhost
  • InvalidArgumentError when using summary in Tensorflow v1.2.1
  • How to check if child component resource exist or not using Sightly in AEM?
  • Convert a Base64 LDIF file to plaintext (for import)
  • How to implement dependency property value inheritance in different control types
  • Can't run grass tools from python script (grass 6.4, python 2.7, win7)
  • How to generate nodes with customized shape?
  • Html.BeginForm inside of Html.BeginForm MVC3
  • Converting a wstring to jstring on Linux
  • Dynamic number of ChildViewControllers for XLPagerTabStrip
  • Http Requests not getting routed to Https NodeJs
  • Scrapy + Selenium + Datepicker
  • Is there a function to calculate the difference between two times and display a relative result?
  • Multiple JSliders reacting to each other to always equal 100 percent
  • “RepeatForUnit” item missing in Calendar entry?
  • Train two models concurrently
  • ClearCase can I use clearexport_ccase/clearimport to copy VOB data to a VOB on a different machine
  • Angular 6 illegal operation on a directory, open '/Users//.npm-global/lib/node_modules/
  • Using XPATH to isolate inline javascript
  • Get last 15 lines from a large file in SFTP with phpseclib [duplicate]
  • Google Compute instance receiving email
  • Do iTunesConnect external testers get updates for *every* uploaded ipa file after Beta Approval?
  • How to run Daphne Server (Django Channels) & workers in the background?
  • Draw 9 patch dotted /dashed line on Android
  • Unable to start a WebView from an AsyncTask
  • Why do you need 2 Javascript files for cross-platform Cordova plugin?
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • Stop an element moving with padding on hover
  • select an input by value?
  • How do I use libcurl to printf a remote FTP directory listing?
  • Multiplying polynomials/simplifying like terms
  • Floating parent div grows to hypothetical width of floating child div
  • I am consuming a WCF service that requires headers from a .NET 2 website. How can I programmatically
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Codeigniniter insert data through models and controller
  • PHP Permalinks.. how to change?
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?