Search code examples
javaspringexceptionlogfactory

NoClassDefFound Exception from org/apache/commons/logging/LogFactory in Spring Tool Suite


I am doing some testing with Spring Tool Suite to familiarize my self with it. I am running a simple persistence test. When I try to run my test I get the following exception. Does anyone have any recommendations on where this is coming from and how to resolve it?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:162)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:90)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.persistencetest.repositories.test.UserRepositoryImplementationTest.main(UserRepositoryImplementationTest.java:17)

I doubt the error is in my code, as this seems to be coming from something internal to Spring. But my code follows.

package com.persistencetest.repositories.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.persistencetest.entities.User;
import com.persistencetest.repositories.UserRepository;
import com.persistencetest.repositories.UserRepositoryImplementation;

public class UserRepositoryImplementationTest {

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        ApplicationContext context = new ClassPathXmlApplicationContext("application-config.xml");

        UserRepository userRepository = context.getBean("userRepository", UserRepositoryImplementation.class);

        User user = context.getBean("user", User.class);

        userRepository.registerUser(user);
    }

}

Solution

  • You need to include the commons-logging JAR or use a logging system that implements it.