开发者社区> 问答> 正文

为Hibernate Session Factory创建sessionFactory时出现Sprin

在Spring MVC配置文件中为hibernate创建sessionFactory时,出现以下错误。

我得到的错误是:

在上下文初始化期间遇到-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/spring-mvc-crud-demo-servlet.xml]中创建名称为'sessionFactory'的bean时出错:调用init方法失败;嵌套异常是java.lang.NoClassDefFoundError:net / bytebuddy / NamingStrategy $ SuffixingRandom $ BaseNameResolver 2019年11月29日PM org.springframework.web.servlet.FrameworkServlet initServletBean严重:上下文初始化失败org.springframework.beans.factory .BeanCreationException:创建在ServletContext资源[/WEB-INF/spring-mvc-crud-demo-servlet.xml]中定义的名称为'sessionFactory'的bean时出错:调用init方法失败;嵌套的异常是java.lang.NoClassDefFoundError:

我的Spring配置文件如下:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- Add support for component scanning -->
    <context:component-scan base-package="com" />

    <!-- Add support for conversion, formatting and validation support -->
    <mvc:annotation-driven/>

    <!-- Define Spring MVC view resolver -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- Step 1: Define Database DataSource / connection pool -->
    <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">
        <property name="driverClass" value="com.mysql.cj.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/web_customer_tracker?useSSL=false&serverTimezone=UTC" />
        <property name="user" value="root" />
        <property name="password" value="DeepMYSQL9046!@" /> 

        <!-- these are connection pool properties for C3P0 -->
        <property name="initialPoolSize" value="5"/>
        <property name="minPoolSize" value="5" />
        <property name="maxPoolSize" value="20" />
        <property name="maxIdleTime" value="30000" />
    </bean>  

    <!-- Step 2: Setup Hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="packagesToScan" value="com" />
        <property name="hibernateProperties">
           <props>
              <prop key="hibernate5.dialect">org.hibernate.dialect.MySQLDialect</prop>
              <prop key="hibernate5.show_sql">true</prop>
           </props>
        </property>
   </bean>    

    <!-- Step 3: Setup Hibernate transaction manager -->
    <bean id="myTransactionManager"
            class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <!-- Step 4: Enable configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="myTransactionManager" />

    <!-- Add support for reading web resources: css, images, js, etc ... -->
    <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>



</beans>

展开
收起
垚tutu 2019-11-29 23:21:21 755 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载