我正在使用Spring Tool Suite进行一些测试,以熟悉我自己。我正在运行一个简单的持久性测试。当我尝试运行测试时,我得到以下异常。有没有人对这里的来源以及解决方法有任何建议?
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)
我怀疑错误是在我的代码中,因为这似乎来自Spring内部的东西。但我的代码如下。
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);
}
}
答案 0 :(得分:3)
您需要包含commons-logging JAR或使用实现它的日志记录系统。