aspose file tools*
The moose likes Spring and the fly likes SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoade Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply locked New topic
Author

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

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 376
I'm using the latest versions of spring, java, eclipse, maven and tomcat and I'm trying to make a minimal example of spring-mvc (using annotations and maven) work.
This symptom seems exactly match http://www.mkyong.com/spring/spring-error-classnotfoundexception-org-springframework-web-context-contextloaderlistener/.



When I try that solution, however, it does not seem to fix my problem. My pom.xml has



and I've tried adding spring-web to the classpath of the open launch configuration as suggested by the above URL: no luck!

I'm developing and launching the server/application with the latest eclipse (indigo sr1) & tomcat & java 1.7.

I hope I have posted enough information for someone to help me.
siegfried
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

You added the dependency in your maven pom file. But does your IDE use it? Is your classpath truly set to that jar file?

Are you using the Eclipse Maven plugin? If so, if you right click on your project, there should be a maven option which you can choose update dependencies to update your project.

Are you also including the jar file in your war or tomcat?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 376
Thank you Mark.

Can you elaborate a bit?
You added the dependency in your maven pom file. But does your IDE use it?

Which dependency? I assume you are talking about spring-web. It is in there with all the other dependencies. Apparently my IDE is using it because I'm not getting compiler errors.

Is your classpath truly set to that jar file?


I thought I did not need to worry about this because Eclipse and maven were supposed to take care of this. All the dependencies in the dependencies section of the pom.xml are put it on the classpath -- correct?

Like I said, I put the spring-web in the tomcat classpath that one specifies with the class path for the launch menu as that article recommended.

Are you using the Eclipse Maven plugin? If so, if you right click on your project, there should be a maven option which you can choose update dependencies to update your project.


Yes this works. I've done it.

Are you also including the jar file in your war or tomcat?


No! I thought maven was supposed to do this.

I have a different spring-mvc project which does not use annotations. That works with maven and tomcat. I just hit "shift-alt-x r" and it works. I presume eclipse is calling maven to build the war and it deploys the war file to tomcat and tomcat runs the compiled java code for the servlet. That works and I'm doing the same thing with this annotated project (except, of course, the annotated project uses this org.springframework.web.context.ContextLoaderListener class).


Thanks
siegfried

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

In your Spring configuration do you have <mvc:annotation-driven/>

Not that that will solve the problem but a java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener

Means that a jar is not in your classpath at runtime. In this case the class is actually a Java EE jar with the ServletContextListener.

Yes, maven should package all your <dependency> jar files in your war as long as the <dependency> is not set to compile. When it is set to compile the jar file is only in your classpath for compile time and not included in your war file. There is also a scope called provided, which means don't include the jar file in your war because it is already provided by the server and therefore in the classpath for your application at runtime.

Hope that helps fix the problem.

Mark
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 376
Thanks Mark.

OK, I'm not using compile. What do I want to use. I tried this and it did not help:



Thanks!
Siegfried
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The only way you can prove that a jar file is in your classpath is to look at the jars that are in the classpath. You get that error if a jar file with the class is not in the classpath, or the class that is is a wrong version, compiled by another java compiler version.

So look at your war file or war directory that gets created and run in your Tomcat. Is that jar file there?

We can't look for you, you need to tell us.

Thanks

Mark
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 376
I'm using eclipse to start and stop tomcat. I believe we are seeing the desired jar files in the desired directories. We see it in in the target directory and we see it in the tomcat server directory (I think).



When I look in this jar file with emacs, I see this line:



I think this means my desired jar file and class are present in the places they need to be. So why is it telling me it cannot find the class?

All I am trying to do is write the "hello world" web page that uses annotations for spring MVC using maven and eclipse. Perhaps someone can recommend an example that works (and uses annotations)? I tried the mvc-basic example on the spring web site and that does not work either. I wish the Spring in Action book or the Spring Recipies book had simple examples. I get compiler errors when I try those spring mvc examples. I've also google searched for other examples. I've tried using the maven archetype for spring mvc and that does not work either.

Thanks
Siegfried
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

OK, the other problem that can occur here is that you have two different versions of the jar file with that class in the classpath. This happens in Maven apps because of secondary/tertiary dependencies. Meaning you have one <dependency> that it has its own pom file in the repo that has its own dependency tags. which might point to a different version of a Spring jar. So you have to add an <ignore> (forgot the tag in Maven) so that it doesn't go down that path, but uses just your jar in your maven pom file.

Hope that helps.

If you look at the jars in the target directory that gets loaded by tomcat in Eclipse, do you see two spring jars one spring-web3.0.5 and one spring-core or spring-all type jar with a different version than 3.0.5?

Unfortunately, because Eclipse makes it really difficult to find all that stuff, it is well hidden, that it is hard to fix and debug. That is why I always run maven and Tomcat in its own command line outside of my IDE. Then I am in more control.

Mark
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 376
I do have another spring servlet/jsp that is working that does not use the annotations or the ContextLoader.

What would be the functions calls in java to retrieve the current list of jars in the class path that (tomcat?) is using to run my servlet? I'd like to modify this one working servlet to display the jars in the class path to confirm my earlier observations from poking around with Windows Explorer.

Thanks
siegfried
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Siegfried Heintze wrote:I do have another spring servlet/jsp that is working that does not use the annotations or the ContextLoader.

What would be the functions calls in java to retrieve the current list of jars in the class path that (tomcat?) is using to run my servlet? I'd like to modify this one working servlet to display the jars in the class path to confirm my earlier observations from poking around with Windows Explorer.

Thanks
siegfried


Don't know of any apis. I just look in the directories of the archive and Tomcat to see what .jar files are in directories that are in the classpath. What are the jars in the war files WEB-INF/libs directory, etc.

Mark
Karan Bhandari
Greenhorn

Joined: Sep 20, 2012
Posts: 1
Try running "mvn -e eclipse:eclipse" from command line in the directory where the parent pom is located
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Karan Bhandari wrote:Try running "mvn -e eclipse:eclipse" from command line in the directory where the parent pom is located


Karan. This is like months ago. Please don't resurrect old threads. Especially this topic, if the OP still had a problem they would have replied since months ago. So it is already resolved.

Closing this thread

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoade
 
Similar Threads
Maven dependencies
java.lang.NoSuchMethodError: HandlerMethodResolver
Transitive Dependency Problem
Maven web project dependencies
Spring Major version '3' expected