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>

Guess you like

Origin blog.csdn.net/d347091231/article/details/120901319