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

创建名称为“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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。