开发者社区> 问答> 正文

Spring 报错,请看详细?报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cnstockFunctionUserDAO' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.orm.hibernate4.HibernateTransactionManager' to required type 'org.hibernate.SessionFactory' for property 'sessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.orm.hibernate4.HibernateTransactionManager] to required type [org.hibernate.SessionFactory] for property 'sessionFactory': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

展开
收起
爱吃鱼的程序员 2020-06-12 15:37:12 480 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    http://bbs.csdn.net/topics/390591322?page=1#post-395571846我的错跟这个不太一样人家要SessionFactory呢你给配置的是org.springframework.orm.hibernate4.HibernateTransactionManager?Causedby:java.lang.IllegalStateException:Cannotconvertvalueoftype[org.springframework.orm.hibernate4.HibernateTransactionManager]torequiredtype[org.hibernate.SessionFactory]forproperty'sessionFactory':nomatchingeditorsorconversionstrategyfound
    atorg.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)
    atorg.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
    ...17more


    <aclass='referer'target='_blank'>@RevenAn你看下这个
    这是我的配置
    <!--配置sessionFactory用于产生Session-->
    <beanid="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
     <!--dataSource-->
     <propertyname="dataSource"ref="dataSource"/> 
     <!--配置扫描实体类包,注意!!!:所有的实体必须在com.pp.passport.bo包下。如果加在别的包下需要修改此处的配置-->
     <propertyname="packagesToScan"> 
      <list> 
        <value>com.pp.passport.bo</value> 
      </list> 
     </property> 
     <!--配置Hibernate方言和是否显示SQL文-->
     <propertyname="hibernateProperties"> 
     <props>
     <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
     <propkey="hibernate.show_sql">true</prop>
     <propkey="hibernate.format_sql">true</prop> 
    </props>
     </property> 
    </bean>


    <!--配置事务管理-->
    <beanid="hibernateTransactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <propertyname="sessionFactory"ref="sessionFactory"/>
    </bean>

    是不是jar包版本不对,用了hibernate3的包?

    hibernate4和hibernate3的配置文件有变更,详细百度. 

    Exceptioninthread"main"org.hibernate.HibernateException:NoSessionfoundforcurrentthread
    atorg.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
    atorg.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:993)
    atcom.pp.passport.dao.impl.CnstockFunctionUserDAOImpl.getFunctionUserByUsername(CnstockFunctionUserDAOImpl.java:52)
    atcom.pp.passport.dao.impl.CnstockFunctionUserDAOImpl.main(CnstockFunctionUserDAOImpl.java:133)

    <divclass='ref'>

    引用来自“顶风鳥一身”的评论


    这是我的配置
    <!--配置sessionFactory用于产生Session-->
    <beanid="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
     <!--dataSource-->
     <propertyname="dataSource"ref="dataSource"/> 
     <!--配置扫描实体类包,注意!!!:所有的实体必须在com.pp.passport.bo包下。如果加在别的包下需要修改此处的配置-->
     <propertyname="packagesToScan"> 
      <list> 
        <value>com.pp.passport.bo</value> 
      </list> 
     </property> 
     <!--配置Hibernate方言和是否显示SQL文-->
     <propertyname="hibernateProperties"> 
     <props>
     <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
     <propkey="hibernate.show_sql">true</prop>
     <propkey="hibernate.format_sql">true</prop> 
    </props>
     </property> 
    </bean>


    <!--配置事务管理-->
    <beanid="hibernateTransactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <propertyname="sessionFactory"ref="sessionFactory"/>
    </bean>

    已经解决注解扫描利用AOP声明式事物方式,为什么还要@Transaction这个注解,不解

    2020-06-12 15:37:30
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载