当前位置: 首页 > 知识库问答 >
问题:

无法实例化bean类annotationsessionfactorybean

钱峻
2023-03-14
5.3.1.Final
: 3.2 cr4
Jan 19, 2020 6:44:42 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@ad9418: startup date [Sun Jan 19 18:44:42 IST 2020]; root of context hierarchy
Jan 19, 2020 6:44:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [resouce/springXML.xml]
Jan 19, 2020 6:44:43 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18e2867: defining beans [bds,sf,ht,dao]; root of factory hierarchy
Jan 19, 2020 6:44:43 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18e2867: defining beans [bds,sf,ht,dao]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sf' defined in class path resource [resouce/springXML.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/hibernate/cfg/AnnotationConfiguration
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:892)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:545)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at test.client.main(client.java:15)
Caused by: 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/hibernate/cfg/AnnotationConfiguration
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:939)
    ... 13 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration
    at org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean.<init>(AnnotationSessionFactoryBean.java:99)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    ... 15 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 21 more

XML文件

            "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
   <bean id="bds" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    <property name="username" value="rayudu"/>
    <property name="password" value="oracle10g"/>
    <property name="maxActive" value="15"/>
    <property name="maxIdle" value="5"/>
    <property name="maxWait" value="5000"/>
    </bean>

    <bean id="sf" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
     <property name="dataSource" ref="bds"/>
     <property name="hibernateProperties">
        <props>
             <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
             <prop key="hibernate.hbm2ddl.auto">create</prop>
             <prop key="hibernate.show_sql">true</prop>
        </props>
     </property>
     <property name="annotatedClasses">
         <list>
            <value>model.Student</value>
         </list>
     </property>
    </bean>

    <bean id="ht" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="sf"/>
    </bean>

    <bean id="dao" class="dap.StudentDAOImp">
    <property name="ht" ref="ht"/>
    </bean> 
</beans>```

*please help me*

共有1个答案

许俊雅
2023-03-14

和随后的错误:

无法实例化bean类[org.springframework.orm.hibernate3.annotation.annotationSessionFactoryBean]:构造函数引发异常;嵌套异常是java.lang.noClassDefFounderRor:org/hibernate/cfg/annotationconfiguration

说全班不在场。可能是您没有添加所需的hibernate依赖项,或者应用程序没有正确构建

 类似资料:
  • 问题内容: 我使用Spring 4.1.6.RELEASE和Spring Data Jpa 1.8.0.RELEASE。我在创建org.springframework.data.domain.Pageable bean时遇到问题。它在我的控制器中使用: 我的应用程序上下文中还有一个下一个xml配置: 最后,我从客户端执行下一个requsr: 在tomcat日志中,我看到下一个: 请帮助我解决此问题

  • 问题内容: 当我尝试运行此代码时: 我收到此错误: 我不明白为什么我无法实例化课程…在我看来似乎是对的… 问题答案: 是一个接口,因此您无法直接实例化它。您可以实例化一个具体的子类,例如:

  • 当我试图运行我的脚本时,我收到以下错误

  • 这是我的黄瓜基类。 在运行这个基类之后,我看到下面的异常。

  • 在此任务中,我不允许使用自动布线

  • 问题内容: 我试图创建一个字符串集,其中填充了哈希表中的键,以便for- each循环可以遍历该Set并将默认值放入哈希表中。我仍在学习Java,但是我尝试做的方式不是有效的语法。有人可以演示这样做的正确方法,并解释为什么我的方法行不通,而他们的方法行得通。 问题答案: 不是类,而是接口。 因此,基本上可以仅实例类实现(,或) 例如 :