为什么会报错呢?

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小蓝 2022-12-23 15:54:53

同学你好,同学提供的报错信息不完整,无法准确判断具体的错误原因。

建议同学阅读一下最后一处Caused by语句的报错信息,通常会在这里有详细的错误说明。如果同学阅读之后依然无法找到原因,建议同学提供完整的报错信息。

祝学习愉快~

  • 提问者 王小east #1

    Caused by语句如下,麻烦老师帮忙看下报错原因

    Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Bean with name 'dataSource' has been injected into other beans [transactionManager] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.

    2022-12-23 16:16:38
  • 好帮手慕小蓝 回复 提问者 王小east #2

    同学你好,从报错信息看,应当是在applicationContext.xml中出现了问题。建议同学检查一下所有使用dataSource和transactionManager的位置是否都书写正确。

    祝学习愉快~

    2022-12-23 16:26:45
  • 提问者 王小east 回复 好帮手慕小蓝 #3

    applicationContext.xml文件如下,没发现有问题呢

    <?xml version="1.0" encoding="UTF-8" ?>
    <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:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            https://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/tx
            https://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop
            https://www.springframework.org/schema/aop/spring-aop.xsd">
    
        <context:component-scan base-package="java"/>
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/hotel?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimeZone=Asia/Shanghai&amp;publicKeyRetrieval=true"/>
            <property name="username" value="root"/>
            <property name="password" value="root"/>
        </bean>
        <bean id="jdbcComplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <bean id="hotelDao" class="dao.HotelDao"/>
        <bean id="hotelService" class="service.HotelService">
            <property name="hotelDao" ref="hotelDao"/>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="batchInsert5" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
    
        <aop:config>
            <aop:pointcut id="pointcut" expression="execution(* *..*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
        </aop:config>
    
    </beans>


    2022-12-23 16:33:26
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师