2

我正在使用 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);
    }

}
4

1 回答 1

3

您需要包含 commons-logging JAR 或使用实现它的日志系统。

于 2012-10-10T18:25:45.230 回答