0

Happy new year to all of you!

I have started a new Spring MVC Project with SpringSource doing click in File > New > Spring Template Project and I have tried to run it in vFabric tc Server and it doesn't work. The first error was about a LOC header in a Spring class so I have changed the Spring version to download. Now I have got the next error:

GRAVE: Excepción enviando evento inicializado de contexto a instancia de escuchador de clase     org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/apache/log4j/Level
    at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) 

I think Spring MVC Project is supposed to run the first time with no need of configuration or solving errors.

I am trying to learn Spring for four months and I don't make any progress. I have got Spring in action which I think is a very good book but not enough practical, so I decided reading Spring MVC Step-by-Step first and I liked it but the example project uses Ant and I would like a MVC project with Maven like Spring MVC Project from SpringSource and again I have lost because Spring MVC Project uses annotations, classes and other configuration that I don't know. I just want to start a project now and learn little to little but nothing works for me.

Could you help me to do the project works and tell me what is the next step to understand that Spring MVC project?? I would like to know what is your experience learning Spring, if you found difficulties, etc.

Thanks.

Jonás
  • 1,459
  • 4
  • 27
  • 43

2 Answers2

0

This is Java 101:

java.lang.NoClassDefFoundError: org/apache/log4j/Level

This means that the log4j.jar is not in the CLASSPATH.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • But log4j is downloaded by Maven and I can see the class Level. Why is not it in the CLASSPATH? – Jonás Jan 02 '12 at 23:32
  • Worry about making it work without Maven, then figure out Maven. You can't write Java without understanding CLASSPATH thoroughly, but you can do without Maven. I never use it. – duffymo Jan 02 '12 at 23:37
0

Check the .classpath file in your project and see if log4j is included . If you have a war , check the exploded war if it has the log4j file . The dependency I include in maven is as follows

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
Aravind A
  • 9,507
  • 4
  • 36
  • 45
  • 1
    I have changed to download the same version. In my .classpath the classpathentry is and after deploying the log4j-1.2.14.jar is included in the WEB-INF\lib directory. Why is this jar missing? – Jonás Jan 03 '12 at 11:33
  • 1
    try an mvn clean eclipse:eclipse , refresh the project and check it . If you open the .classpath you should see an entry similar to . You could also package the project into a war and open the war and see if log4j jar gets in . For learning spring, try deploying the [petclinic](http://static.springsource.org/docs/petclinic.html) samples provided by spring . – Aravind A Jan 03 '12 at 12:09
  • I did it and the error now is about ClassNotFoundException ContextLoaderListener – Jonás Jan 03 '12 at 22:15
  • 1
    @honix . Wish I could see your project setup . Do you have the necessary dependencies in your project ? The ContextLoaderListener is in the spring-web jar . Add the dependency for that if it is missing .It's different from spring-webmvc jar . See this [link](http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl) for other approaches . – Aravind A Jan 04 '12 at 05:11
  • You can see the project if you have STS 3.8.1. I just created a new Spring MVC Project and I didn't modify anything. This is disappointing for me because I understand that a new project is supposed to run properly. Thanks for all you attention and support. – Jonás Jan 04 '12 at 13:06