areadao注入失败
areadaotest可以成功运行,但是areadao显示注入失败,为什么?
控制台报文如下:
E:\JDK\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:49292,suspend=y,server=n -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2020.3\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\IDEA\IntelliJ IDEA 2020.3\lib\idea_rt.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-launcher\1.7.2\junit-platform-launcher-1.7.2.jar;C:\Users\Administrator\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-engine\1.7.2\junit-platform-engine-1.7.2.jar;C:\Users\Administrator\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\Administrator\.m2\repository\org\junit\platform\junit-platform-commons\1.7.2\junit-platform-commons-1.7.2.jar;D:\IDEA\IntelliJ IDEA 2020.3\plugins\junit\lib\junit5-rt.jar;D:\IDEA\IntelliJ IDEA 2020.3\plugins\junit\lib\junit-rt.jar;E:\IDEAworkspace\o2oboot\o2oboot\target\test-classes;E:\IDEAworkspace\o2oboot\o2oboot\target\classes;E:\maven-repo\org\springframework\boot\spring-boot-starter-web\2.5.6\spring-boot-starter-web-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter\2.5.6\spring-boot-starter-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot\2.5.6\spring-boot-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot-autoconfigure\2.5.6\spring-boot-autoconfigure-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter-logging\2.5.6\spring-boot-starter-logging-2.5.6.jar;E:\maven-repo\org\apache\logging\log4j\log4j-to-slf4j\2.14.1\log4j-to-slf4j-2.14.1.jar;E:\maven-repo\org\apache\logging\log4j\log4j-api\2.14.1\log4j-api-2.14.1.jar;E:\maven-repo\org\slf4j\jul-to-slf4j\1.7.32\jul-to-slf4j-1.7.32.jar;E:\maven-repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\maven-repo\org\yaml\snakeyaml\1.28\snakeyaml-1.28.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter-json\2.5.6\spring-boot-starter-json-2.5.6.jar;E:\maven-repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.12.5\jackson-datatype-jdk8-2.12.5.jar;E:\maven-repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.12.5\jackson-datatype-jsr310-2.12.5.jar;E:\maven-repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.12.5\jackson-module-parameter-names-2.12.5.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter-tomcat\2.5.6\spring-boot-starter-tomcat-2.5.6.jar;E:\maven-repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.54\tomcat-embed-core-9.0.54.jar;E:\maven-repo\org\apache\tomcat\embed\tomcat-embed-el\9.0.54\tomcat-embed-el-9.0.54.jar;E:\maven-repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.54\tomcat-embed-websocket-9.0.54.jar;E:\maven-repo\org\springframework\spring-web\5.3.12\spring-web-5.3.12.jar;E:\maven-repo\org\springframework\spring-beans\5.3.12\spring-beans-5.3.12.jar;E:\maven-repo\org\springframework\spring-webmvc\5.3.12\spring-webmvc-5.3.12.jar;E:\maven-repo\org\springframework\spring-aop\5.3.12\spring-aop-5.3.12.jar;E:\maven-repo\org\springframework\spring-context\5.3.12\spring-context-5.3.12.jar;E:\maven-repo\org\springframework\spring-expression\5.3.12\spring-expression-5.3.12.jar;E:\maven-repo\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.1\mybatis-spring-boot-starter-1.3.1.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter-jdbc\2.5.6\spring-boot-starter-jdbc-2.5.6.jar;E:\maven-repo\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;E:\maven-repo\org\springframework\spring-jdbc\5.3.12\spring-jdbc-5.3.12.jar;E:\maven-repo\org\springframework\spring-tx\5.3.12\spring-tx-5.3.12.jar;E:\maven-repo\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.1\mybatis-spring-boot-autoconfigure-1.3.1.jar;E:\maven-repo\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;E:\maven-repo\org\mybatis\mybatis-spring\1.3.1\mybatis-spring-1.3.1.jar;E:\maven-repo\org\springframework\boot\spring-boot-starter-test\2.5.6\spring-boot-starter-test-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot-test\2.5.6\spring-boot-test-2.5.6.jar;E:\maven-repo\org\springframework\boot\spring-boot-test-autoconfigure\2.5.6\spring-boot-test-autoconfigure-2.5.6.jar;E:\maven-repo\com\jayway\jsonpath\json-path\2.5.0\json-path-2.5.0.jar;E:\maven-repo\net\minidev\json-smart\2.4.7\json-smart-2.4.7.jar;E:\maven-repo\net\minidev\accessors-smart\2.4.7\accessors-smart-2.4.7.jar;E:\maven-repo\org\ow2\asm\asm\9.1\asm-9.1.jar;E:\maven-repo\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;E:\maven-repo\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;E:\maven-repo\org\assertj\assertj-core\3.19.0\assertj-core-3.19.0.jar;E:\maven-repo\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;E:\maven-repo\org\junit\jupiter\junit-jupiter\5.7.2\junit-jupiter-5.7.2.jar;E:\maven-repo\org\junit\jupiter\junit-jupiter-api\5.7.2\junit-jupiter-api-5.7.2.jar;E:\maven-repo\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;E:\maven-repo\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;E:\maven-repo\org\junit\platform\junit-platform-commons\1.7.2\junit-platform-commons-1.7.2.jar;E:\maven-repo\org\junit\jupiter\junit-jupiter-params\5.7.2\junit-jupiter-params-5.7.2.jar;E:\maven-repo\org\junit\jupiter\junit-jupiter-engine\5.7.2\junit-jupiter-engine-5.7.2.jar;E:\maven-repo\org\junit\platform\junit-platform-engine\1.7.2\junit-platform-engine-1.7.2.jar;E:\maven-repo\org\mockito\mockito-core\3.9.0\mockito-core-3.9.0.jar;E:\maven-repo\net\bytebuddy\byte-buddy\1.10.22\byte-buddy-1.10.22.jar;E:\maven-repo\net\bytebuddy\byte-buddy-agent\1.10.22\byte-buddy-agent-1.10.22.jar;E:\maven-repo\org\objenesis\objenesis\3.2\objenesis-3.2.jar;E:\maven-repo\org\mockito\mockito-junit-jupiter\3.9.0\mockito-junit-jupiter-3.9.0.jar;E:\maven-repo\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;E:\maven-repo\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;E:\maven-repo\org\springframework\spring-core\5.3.12\spring-core-5.3.12.jar;E:\maven-repo\org\springframework\spring-jcl\5.3.12\spring-jcl-5.3.12.jar;E:\maven-repo\org\springframework\spring-test\5.3.12\spring-test-5.3.12.jar;E:\maven-repo\org\xmlunit\xmlunit-core\2.8.3\xmlunit-core-2.8.3.jar;E:\maven-repo\ch\qos\logback\logback-classic\1.2.6\logback-classic-1.2.6.jar;E:\maven-repo\ch\qos\logback\logback-core\1.2.6\logback-core-1.2.6.jar;E:\maven-repo\org\slf4j\slf4j-api\1.7.32\slf4j-api-1.7.32.jar;E:\maven-repo\javax\servlet\javax.servlet-api\4.0.1\javax.servlet-api-4.0.1.jar;E:\maven-repo\com\fasterxml\jackson\core\jackson-databind\2.12.5\jackson-databind-2.12.5.jar;E:\maven-repo\com\fasterxml\jackson\core\jackson-annotations\2.12.5\jackson-annotations-2.12.5.jar;E:\maven-repo\com\fasterxml\jackson\core\jackson-core\2.12.5\jackson-core-2.12.5.jar;E:\maven-repo\commons-collections\commons-collections\3.2\commons-collections-3.2.jar;E:\maven-repo\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar;E:\maven-repo\c3p0\c3p0\0.9.1.2\c3p0-0.9.1.2.jar;E:\maven-repo\net\coobird\thumbnailator\0.4.8\thumbnailator-0.4.8.jar;E:\maven-repo\com\github\penggle\kaptcha\2.3.2\kaptcha-2.3.2.jar;E:\maven-repo\com\jhlabs\filters\2.0.235-1\filters-2.0.235-1.jar;E:\maven-repo\commons-fileupload\commons-fileupload\1.3.2\commons-fileupload-1.3.2.jar;E:\maven-repo\commons-io\commons-io\2.2\commons-io-2.2.jar;E:\maven-repo\redis\clients\jedis\3.6.3\jedis-3.6.3.jar;E:\maven-repo\org\apache\commons\commons-pool2\2.9.0\commons-pool2-2.9.0.jar;E:\maven-repo\com\google\zxing\javase\3.3.0\javase-3.3.0.jar;E:\maven-repo\com\google\zxing\core\3.3.0\core-3.3.0.jar;E:\maven-repo\com\beust\jcommander\1.48\jcommander-1.48.jar;E:\maven-repo\com\github\jai-imageio\jai-imageio-core\1.3.1\jai-imageio-core-1.3.1.jar;E:\maven-repo\org\quartz-scheduler\quartz\2.3.0\quartz-2.3.0.jar;E:\maven-repo\com\mchange\mchange-commons-java\0.2.11\mchange-commons-java-0.2.11.jar;E:\maven-repo\com\alibaba\fastjson\1.2.45\fastjson-1.2.45.jar;E:\maven-repo\com\squareup\okhttp3\okhttp\3.9.1\okhttp-3.9.1.jar;E:\maven-repo\com\squareup\okio\okio\1.13.0\okio-1.13.0.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.imooc.o2o.dao.AreaDaoTest,testQueryArea
Connected to the target VM, address: '127.0.0.1:49292', transport: 'socket'
2021-10-27 05:32:30.204 [main] INFO o.s.b.t.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.imooc.o2o.dao.AreaDaoTest], using SpringBootContextLoader
2021-10-27 05:32:30.220 [main] INFO o.s.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.imooc.o2o.dao.AreaDaoTest]: no resource found for suffixes {-context.xml, Context.groovy}.
2021-10-27 05:32:30.235 [main] INFO o.s.t.c.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.imooc.o2o.dao.AreaDaoTest]: AreaDaoTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
2021-10-27 05:32:30.859 [main] INFO o.s.b.t.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.imooc.o2o.O2obootApplication for test class com.imooc.o2o.dao.AreaDaoTest
2021-10-27 05:32:31.296 [main] INFO o.s.b.t.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
2021-10-27 05:32:31.452 [main] INFO o.s.b.t.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@790174f2, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@42257bdd, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@7689ddef, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@687a762c, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@1a2e2935, org.springframework.test.context.support.DirtiesContextTestExecutionListener@733c423e, org.springframework.test.context.transaction.TransactionalTestExecutionListener@4b629f13, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@70925b45, org.springframework.test.context.event.EventPublishingTestExecutionListener@1b9ea3e3, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@aa22f1c, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@55e7a35c, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@37cd92d6, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@5922ae77, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@4263b080, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@2af616d3]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2021-10-27 05:32:32.700 [main] INFO com.imooc.o2o.dao.AreaDaoTest - Starting AreaDaoTest using Java 11.0.5 on 8PA12GBLYDQHVJ1 with PID 6188 (started by Administrator in E:\IDEAworkspace\o2oboot\o2oboot)
2021-10-27 05:32:32.731 [main] DEBUG com.imooc.o2o.dao.AreaDaoTest - Running with Spring Boot v2.5.6, Spring v5.3.12
2021-10-27 05:32:32.778 [main] INFO com.imooc.o2o.dao.AreaDaoTest - No active profile set, falling back to default profiles: default
2021-10-27 05:32:36.725 [main] INFO com.mchange.v2.log.MLog - MLog clients using java 1.4+ standard logging.
2021-10-27 05:32:37.286 [main] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector (file:/E:/maven-repo/org/mybatis/mybatis/3.4.5/mybatis-3.4.5.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-10-27 05:32:42.045 [main] INFO com.imooc.o2o.dao.AreaDaoTest - Started AreaDaoTest in 10.4 seconds (JVM running for 17.251)
2021-10-27 05:32:43.714 [main] INFO c.m.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 2, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 10000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge152ak1gv1lwzm9jjj2|40a72ecd, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.cj.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge152ak1gv1lwzm9jjj2|40a72ecd, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/o2o?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {password=******, user=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
2021-10-27 05:32:44.509 [main] DEBUG com.imooc.o2o.dao.AreaDao.queryArea - ==> Preparing: SELECT area_id, area_name, priority, create_time, last_edit_time FROM tb_area ORDER BY priority DESC
2021-10-27 05:32:44.603 [main] DEBUG com.imooc.o2o.dao.AreaDao.queryArea - ==> Parameters:
2021-10-27 05:32:44.915 [main] DEBUG com.imooc.o2o.dao.AreaDao.queryArea - <== Total: 5
Disconnected from the target VM, address: '127.0.0.1:49292', transport: 'socket'
Process finished with exit code 0
源码如下:
package com.imooc.o2o.dao;
import com.imooc.o2o.entity.Area;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
public class AreaDaoTest {
@Autowired
private AreaDao areaDao;此处报错,但是程序又能成功运行
@Test
public void testQueryArea(){
List<Area> areaList = areaDao.queryArea();
assertEquals(5, areaList.size());
}
}
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星