用AnnotationSessionFactoryBean生成sessionFactory时报错不能创建sessionFactoyBean(转)

本文记录了一个Spring配置中因缺少dom4j.jar和jta.jar导致的NoClassDefFoundError异常,并给出了具体的解决办法。

报错信息:

[junit] Testcase: testCreateFileInfo(springmp3.service.FileDaoImplTests):Caused an ERROR
    [junit]
Error creating bean with name 'sessionFactory' defined in URL [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    [junit] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException
    [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:813)
    [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:769)
    [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:412)
    [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
    [junit] at java.security.AccessController.doPrivileged(Native Method)

spring配置信息:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>domain.FileInfo</value>
</list>
</property>

DAO方法:

public class FileDaoImplTests extends AbstractTransactionalDataSourceSpringContextTests {


   public void testCreateFileInfo() throws Exception{
       
   FileInfo inf = new FileInfo();
   // Arbitrary test information for this "file"
   inf.setFilename("FILE NAME");
   inf.setTitle("TITLE");
   inf.setComment("TEST COMMENT");
  
   assertNull("ID shall not be zero",inf.getId());
  
  
   FileDaoImpl dao = new FileDaoImpl();
   // making the fileinfo persistent in database:
   Integer res = dao.SaveFileInfo(inf);
   assertTrue("wrong result by FileDaoImpl",res.intValue()>0);
   assertNotNull("ID must be non-zero",inf.getId());
   }
  
    @Override
    protected String[] getConfigLocations() {
        return new String[]{"applicationContext.xml"};
    }
}

原因是我没有导入spring_home\lib\dom4j\下的dom4j.jar和jta.jar,导入即可!

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值