11

I am doing a simple Spring MVC application(not using maven) which will print hello world on browser. It is a dynamic project in eclipse, so I put all the required jar files IN both build path as well as in WEB-INF/lib folder

I tried two solutions and both didn't work.

Solutions I found:

  1. cleaning tomcat work directory
  2. putting spring-mvc/spring-web.jar jar file in lib

Here is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</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>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

and there is no typo mistake in configuring the contextLoaderListener, then what is the problem, is there any other solution

Jan 20, 2014 8:16:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 20, 2014 8:16:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.11
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
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:4618)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 20, 2014 8:16:40 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/SpringSample] startup failed due to previous errors
Jan 20, 2014 8:16:40 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8081"]
Jan 20, 2014 8:16:40 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 20, 2014 8:16:40 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4010 ms

eventually I am getting 404 error as my service is failed to loaded

David Mohundro
  • 11,922
  • 5
  • 40
  • 44
Sudip7
  • 2,384
  • 3
  • 27
  • 35
  • By `lib`, do you mean `WEB-INF/lib`? – Sotirios Delimanolis Jan 20 '14 at 15:27
  • possible duplicate of [java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener](http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl) – Yuval Mar 25 '15 at 11:55

5 Answers5

25

I had this same problem in Eclipse. When I would do a maven clean install and move the generated WAR file to my Tomcat webapp folder it would run with no problems. However, inorder to debug I wanted to run in Eclipse but it would throw the following error.

SEVERE: Error configuring application listener of class   org.springframework.web.context.ContextLoaderListener

I googled around until I found the following blog post.

http://commonexceptions.blogspot.com/2014/01/java.html

As the author explains:

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.

See the post for the solution. It is a simple eclipse Deployment Assembly configuration fix. Took me about 30 seconds and now I can debug my Spring webapp in Eclipse.

Here are the relevant steps from the post:

Adding Maven dependencies in project web deployment assembly :

  • Open project properties(example: In project explorer rightClick 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
  • click "Finish".
  • Now the "Maven Dependencies" should be added to the Web Deployment Assembly and it should run.

When using Eclipse WDT and using unmodified and previously working project :

  • 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

The above solution should resolve the exception.

DLeh
  • 23,806
  • 16
  • 84
  • 128
AllanT
  • 923
  • 11
  • 23
  • 2
    Thanks, after hours of screwing around trying to convert an existing java project to a dynamic web project in eclipse this got it working. – Jason Sep 03 '14 at 17:22
  • Answers like this make SO so good. Thanks Allan. God bless you man. – Sushant Gupta Feb 01 '17 at 11:58
  • Initially My application was working fine. But after restart eclipse why I need to follow this steps, I didn't get. I didn't changed the maven/pom.xml or any setting. Can you guide? – Nilesh Aug 15 '17 at 20:28
  • Thanks, "clean tomcat work directory" and "clean" work for me! – frank Mar 20 '18 at 15:40
2

Try to put the spring-web.jar file directly in the WEB-INF/lib (WEB-INF/lib/spring-web.jar) and not in WEB-INF/lib/spring-mvc/spring-web.jar

Rida BENHAMMANE
  • 4,111
  • 1
  • 14
  • 25
1

If you are creating simple project without maven, need to follow following steps,

  1. download required jar files, e.g. I am using spring 4 so I have downloaded files from Index of release

  2. Then add this files inside your WebContent/WEB-INF/lib folder.

  3. Add jar files in build path (In eclipse : Right click on project -> Properties -> Java Build Path -> Add JARs...)

This will avoid org.springframework.web.context.ContextLoaderListener exception.

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
1

I have a VERY GOOD WAY to help you learn Spring MVC if you have Maven up and running.

IF SO: go to your command line (Cygwin) I use...

mvn archetype:generate It will ask for an 'archetype number'. For you... type 16 Enter the group ID which is just the main package. Enter Artifact ID which is your project name. SNAP-SHOT --- just press enter and same with version. Package - is the same as your group ID name. EX: com.spring Confirm it by entering the letter 'y' and press enter. DO all of the above after your are in your workspace directory. That way it is created there. You can do "mvn eclipse:eclipse" to load it in Eclipse OR you can just import it. I prefer the old fashioned importing an existing project.

Everything will be 'already' set up for you in terms of ALL configuration (Java-Based) which is good for you. It will have all the Maven dependencies you need as well already in your pom.xml. You can add or take from it if you want.

The point here is that you will have a running project already and you can play with it from there. I create all my projects like this at first and erase what I don't need and add what I do and then go from there.

Good luck!!!

1

It's a dependency problem, some dependencies are missing in the artifact. My solution in IntelliJ:

Right Click on project name ->open module settings -> problems -> add missing dependencies to the artifact

Restart the server (my case was tomcat)

Hope it helps