0

我正在做一个春季项目,我正在编写我的 junit 测试用例以删除我的一些测试数据,但我收到以下错误..

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined

我的 junit 测试如下所示:

public class TestRemoveTestData implements BeanFactoryAware {

    static boolean functionReturn;

    String user = "xxxx@aol.com.dev";

    private BeanFactory beanFactory;

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;

    }

    @Autowired
    private SessionFactory sessionFactory;


    @Test
    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public void RemoveEnrollmentRecord()
    {
        Session mySession = sessionFactory.getCurrentSession();
        //
        // Get profile record based on email address
        //
        Profile myProfile = (Profile) mySession.createCriteria(Profile.class)
                .add(Restrictions.like("email", user)).uniqueResult();
        //
        // Start to create a new Enrollment Record with a status of "U"
        //
        Enrollment newEnrollment = new Enrollment();
        newEnrollment.setProfile_id(myProfile.getProfile_id());
        newEnrollment.setContact_id(myProfile.getContact_id());
        mySession.delete(newEnrollment);
        mySession.flush();
    }
}
4

1 回答 1

0

您需要加载配置文件。例如,在我的带有 JPA 和 spring security 的 spring 项目中,我的配置文件是 applicationContext.xml、applicationContext-security.xml、applicationContext-jpa.xml。您可以按如下方式加载它们:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/META-INF/spring/applicationContext*.xml"})
public class TestRemoveTestData implements BeanFactoryAware {
 ...

}

注意:我使用通配符“*”来加载我的所有配置文件。但是您可以将它们列在位置={"file1","file2",...}

于 2013-01-30T15:55:29.367 回答