Spring5-MySQL-报错Property ‘dataSource‘ is required

部分错误信息:最主要的是Property 'dataSource' is required

D:\jdk\jdk\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=4564:D:\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar;D:\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit-rt.jar;D:\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit5-rt.jar;D:\jdk\jdk\jre\lib\charsets.jar;D:\jdk\jdk\jre\lib\deploy.jar;D:\jdk\jdk\jre\lib\ext\access-bridge-32.jar;D:\jdk\jdk\jre\lib\ext\cldrdata.jar;D:\jdk\jdk\jre\lib\ext\dnsns.jar;D:\jdk\jdk\jre\lib\ext\jaccess.jar;D:\jdk\jdk\jre\lib\ext\jfxrt.jar;D:\jdk\jdk\jre\lib\ext\localedata.jar;D:\jdk\jdk\jre\lib\ext\nashorn.jar;D:\jdk\jdk\jre\lib\ext\sunec.jar;D:\jdk\jdk\jre\lib\ext\sunjce_provider.jar;D:\jdk\jdk\jre\lib\ext\sunmscapi.jar;D:\jdk\jdk\jre\lib\ext\sunpkcs11.jar;D:\jdk\jdk\jre\lib\ext\zipfs.jar;D:\jdk\jdk\jre\lib\javaws.jar;D:\jdk\jdk\jre\lib\jce.jar;D:\jdk\jdk\jre\lib\jfr.jar;D:\jdk\jdk\jre\lib\jfxswt.jar;D:\jdk\jdk\jre\lib\jsse.jar;D:\jdk\jdk\jre\lib\management-agent.jar;D:\jdk\jdk\jre\lib\plugin.jar;D:\jdk\jdk\jre\lib\resources.jar;D:\jdk\jdk\jre\lib\rt.jar;D:\IDEA\spring5_demo4\out\production\spring5_demo4;D:\IDEA\spring5_demo4\lib\commons-logging-1.1.1.jar;D:\IDEA\spring5_demo4\lib\spring-beans-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-context-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-core-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-expression-5.2.6.RELEASE.jar;C:\Users\34709\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\34709\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\IDEA\spring5_demo4\lib\druid-1.1.9.jar;D:\IDEA\spring5_demo4\lib\spring-aop-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\com.springsource.net.sf.cglib-2.2.0.jar;D:\IDEA\spring5_demo4\lib\com.springsource.org.aopalliance-1.0.0.jar;D:\IDEA\spring5_demo4\lib\com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-aspects-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\mysql-connector-java-8.0.23.jar;D:\IDEA\spring5_demo4\lib\spring-jdbc-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-orm-5.2.6.RELEASE.jar;D:\IDEA\spring5_demo4\lib\spring-tx-5.2.6.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.atguigu.spring5.test.TestBook,testJdbcTemplate
十月 22, 2021 10:39:21 上午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookDaoImpl': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTemplate' defined in class path resource [bean3.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookDaoImpl': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTemplate' defined in class path resource [bean3.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required

	
Caused by: java.lang.IllegalArgumentException: Property 'dataSource' is required
	at org.springframework.jdbc.support.JdbcAccessor.afterPropertiesSet(JdbcAccessor.java:160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
	... 47 more


Process finished with exit code -1

这是因为我们配置dataSource后没有连接需要添加如<!-- JdbcTemplate对象 -->代码

    <!-- JdbcTemplate对象 -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小巫医初春

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值