qq_36825856 2018-04-13 00:53 采纳率: 50%
浏览 3988
已采纳

创建名称为“sessionFactory”的bean时出错

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustomerDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [config/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [config/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

    <!--配置spring创建容器时要扫描的包  -->
    <context:component-scan base-package="cn.wt"></context:component-scan>
    <!--配置HibernateTemplate  -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!--配置sessionFactory  -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <!--配置可选配置  -->
        <property name="hibernateProperties">
            <props>
                <!--显示sql语句  -->
                <prop key="hibernate.show_sql">true</prop>
                <!--输出sql格式 -->
                <prop key="hibernate.format_sql">true</prop>
                <!--有表时更新,无表时创建 -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <!--数据库方言  -->
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <!--配置连接池  -->
                <!-- <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> -->
                <!--配置线程绑定,使一个线程只有一个session  -->
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
            </props>
        </property>
        <property name="packagesToScan">
                <array>
                    <value>cn.wt.entity</value>
                </array>
        </property>
    </bean>

    <!--配置数据源  -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://Localhost:3306/hibernate1"></property>
        <property name="user" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>

  • 写回答

4条回答 默认 最新

  • 奋斗的小杨 2018-04-13 01:13
    关注

    看看CustomerDao 这个类有没有加上注解@Respository

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 51寻迹小车定点寻迹
  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件