ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
Problem :
We come across this common exception when using Java Spring application.
Exception I Encountered Was :
###################################################################################################################
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)###################################################################################################################
Solution :
This exception was caused when i did not add the maven dependencies to the build path. I was using eclipse with maven, so had to include the maven dependencies in the build path as explained below.
Example :
- Adding Maven dependencies in project web deployment assembly :
- Open project properties(example: In project explorer right Click on project name to select "Properties").
- Select "Deployment Assembly".
- Click "Add..." button on the right navigation.
- Select "Java Build Path Entries" from menu of Directive Type and then click "Next".
- Select "Maven Dependencies" from Java Build Path Entries menu and then click "Finish". Now the "Maven Dependencies" should be added to the Web Deployment Assembly.
- If Tomcat is running Stop it
- Open the "Servers" view: Window then select "Show view" and then select "Other" > Server > Servers
- Right Click on the Tomcat Server and then select "Clean Tomcat Work Directory".
- Right Click on the Tomcat Server and then select "Clean"
- Restart the Tomcat Server
Similar Exception :
- ERROR: org.springframework.web.context.ContextLoader - Context initialization failed - java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
No comments:
Post a Comment