【报错】Neither @ContextConfiguration nor @ContextHierarchy found for test class

项目场景:

使用elasticsearch的桶聚合,查找城市、品牌、酒店星级的聚合结果


问题描述

完整报错:

C:\Users\HONOR\.jdks\openjdk-17.0.2\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\IntelliJIdeaProfessional\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar=51998:D:\IntelliJIdeaProfessional\IntelliJ IDEA 2021.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\HONOR\.m2\repository\org\junit\platform\junit-platform-launcher\1.6.3\junit-platform-launcher-1.6.3.jar;D:\IntelliJIdeaProfessional\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar;D:\IntelliJIdeaProfessional\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit5-rt.jar;D:\IntelliJIdeaProfessional\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit-rt.jar;D:\itcast\hotel-demo\target\test-classes;D:\itcast\hotel-demo\target\classes;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.3.10.RELEASE\spring-boot-starter-web-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter\2.3.10.RELEASE\spring-boot-starter-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot\2.3.10.RELEASE\spring-boot-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.3.10.RELEASE\spring-boot-starter-logging-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\HONOR\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\HONOR\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;C:\Users\HONOR\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\HONOR\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\HONOR\.m2\repository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.3.10.RELEASE\spring-boot-starter-json-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.11.4\jackson-databind-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.4\jackson-annotations-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.11.4\jackson-core-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.4\jackson-datatype-jdk8-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.4\jackson-datatype-jsr310-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.4\jackson-module-parameter-names-2.11.4.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.3.10.RELEASE\spring-boot-starter-tomcat-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.45\tomcat-embed-core-9.0.45.jar;C:\Users\HONOR\.m2\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;C:\Users\HONOR\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.45\tomcat-embed-websocket-9.0.45.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-web\5.2.14.RELEASE\spring-web-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-beans\5.2.14.RELEASE\spring-beans-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-webmvc\5.2.14.RELEASE\spring-webmvc-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-aop\5.2.14.RELEASE\spring-aop-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-context\5.2.14.RELEASE\spring-context-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-expression\5.2.14.RELEASE\spring-expression-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\com\baomidou\mybatis-plus-boot-starter\3.4.2\mybatis-plus-boot-starter-3.4.2.jar;C:\Users\HONOR\.m2\repository\com\baomidou\mybatis-plus\3.4.2\mybatis-plus-3.4.2.jar;C:\Users\HONOR\.m2\repository\com\baomidou\mybatis-plus-extension\3.4.2\mybatis-plus-extension-3.4.2.jar;C:\Users\HONOR\.m2\repository\com\baomidou\mybatis-plus-core\3.4.2\mybatis-plus-core-3.4.2.jar;C:\Users\HONOR\.m2\repository\com\baomidou\mybatis-plus-annotation\3.4.2\mybatis-plus-annotation-3.4.2.jar;C:\Users\HONOR\.m2\repository\com\github\jsqlparser\jsqlparser\4.0\jsqlparser-4.0.jar;C:\Users\HONOR\.m2\repository\org\mybatis\mybatis\3.5.6\mybatis-3.5.6.jar;C:\Users\HONOR\.m2\repository\org\mybatis\mybatis-spring\2.0.5\mybatis-spring-2.0.5.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.3.10.RELEASE\spring-boot-autoconfigure-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.3.10.RELEASE\spring-boot-starter-jdbc-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-jdbc\5.2.14.RELEASE\spring-jdbc-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-tx\5.2.14.RELEASE\spring-tx-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\mysql\mysql-connector-java\8.0.26\mysql-connector-java-8.0.26.jar;C:\Users\HONOR\.m2\repository\org\projectlombok\lombok\1.18.20\lombok-1.18.20.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\client\elasticsearch-rest-high-level-client\7.12.1\elasticsearch-rest-high-level-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch\7.12.1\elasticsearch-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-core\7.12.1\elasticsearch-core-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-secure-sm\7.12.1\elasticsearch-secure-sm-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-x-content\7.12.1\elasticsearch-x-content-7.12.1.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-smile\2.11.4\jackson-dataformat-smile-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.11.4\jackson-dataformat-yaml-2.11.4.jar;C:\Users\HONOR\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-cbor\2.11.4\jackson-dataformat-cbor-2.11.4.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-geo\7.12.1\elasticsearch-geo-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-core\8.8.0\lucene-core-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-analyzers-common\8.8.0\lucene-analyzers-common-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-backward-codecs\8.8.0\lucene-backward-codecs-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-grouping\8.8.0\lucene-grouping-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-highlighter\8.8.0\lucene-highlighter-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-join\8.8.0\lucene-join-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-memory\8.8.0\lucene-memory-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-misc\8.8.0\lucene-misc-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-queries\8.8.0\lucene-queries-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-queryparser\8.8.0\lucene-queryparser-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-sandbox\8.8.0\lucene-sandbox-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-spatial-extras\8.8.0\lucene-spatial-extras-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-spatial3d\8.8.0\lucene-spatial3d-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\apache\lucene\lucene-suggest\8.8.0\lucene-suggest-8.8.0.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-cli\7.12.1\elasticsearch-cli-7.12.1.jar;C:\Users\HONOR\.m2\repository\net\sf\jopt-simple\jopt-simple\5.0.2\jopt-simple-5.0.2.jar;C:\Users\HONOR\.m2\repository\com\carrotsearch\hppc\0.8.1\hppc-0.8.1.jar;C:\Users\HONOR\.m2\repository\joda-time\joda-time\2.10.4\joda-time-2.10.4.jar;C:\Users\HONOR\.m2\repository\com\tdunning\t-digest\3.2\t-digest-3.2.jar;C:\Users\HONOR\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\HONOR\.m2\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\jna\5.7.0-1\jna-5.7.0-1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\elasticsearch-plugin-classloader\7.12.1\elasticsearch-plugin-classloader-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\client\elasticsearch-rest-client\7.12.1\elasticsearch-rest-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;C:\Users\HONOR\.m2\repository\org\apache\httpcomponents\httpcore\4.4.14\httpcore-4.4.14.jar;C:\Users\HONOR\.m2\repository\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;C:\Users\HONOR\.m2\repository\org\apache\httpcomponents\httpcore-nio\4.4.14\httpcore-nio-4.4.14.jar;C:\Users\HONOR\.m2\repository\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\plugin\mapper-extras-client\7.12.1\mapper-extras-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\plugin\parent-join-client\7.12.1\parent-join-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\plugin\aggs-matrix-stats-client\7.12.1\aggs-matrix-stats-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\plugin\rank-eval-client\7.12.1\rank-eval-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\org\elasticsearch\plugin\lang-mustache-client\7.12.1\lang-mustache-client-7.12.1.jar;C:\Users\HONOR\.m2\repository\com\github\spullara\mustache\java\compiler\0.9.6\compiler-0.9.6.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-starter-test\2.3.10.RELEASE\spring-boot-starter-test-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-test\2.3.10.RELEASE\spring-boot-test-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.3.10.RELEASE\spring-boot-test-autoconfigure-2.3.10.RELEASE.jar;C:\Users\HONOR\.m2\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;C:\Users\HONOR\.m2\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;C:\Users\HONOR\.m2\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;C:\Users\HONOR\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\HONOR\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\HONOR\.m2\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;C:\Users\HONOR\.m2\repository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;C:\Users\HONOR\.m2\repository\org\assertj\assertj-core\3.16.1\assertj-core-3.16.1.jar;C:\Users\HONOR\.m2\repository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;C:\Users\HONOR\.m2\repository\org\junit\jupiter\junit-jupiter\5.6.3\junit-jupiter-5.6.3.jar;C:\Users\HONOR\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.3\junit-jupiter-api-5.6.3.jar;C:\Users\HONOR\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\HONOR\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\HONOR\.m2\repository\org\junit\platform\junit-platform-commons\1.6.3\junit-platform-commons-1.6.3.jar;C:\Users\HONOR\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.6.3\junit-jupiter-params-5.6.3.jar;C:\Users\HONOR\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.3\junit-jupiter-engine-5.6.3.jar;C:\Users\HONOR\.m2\repository\org\junit\platform\junit-platform-engine\1.6.3\junit-platform-engine-1.6.3.jar;C:\Users\HONOR\.m2\repository\org\mockito\mockito-core\3.3.3\mockito-core-3.3.3.jar;C:\Users\HONOR\.m2\repository\net\bytebuddy\byte-buddy\1.10.22\byte-buddy-1.10.22.jar;C:\Users\HONOR\.m2\repository\net\bytebuddy\byte-buddy-agent\1.10.22\byte-buddy-agent-1.10.22.jar;C:\Users\HONOR\.m2\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;C:\Users\HONOR\.m2\repository\org\mockito\mockito-junit-jupiter\3.3.3\mockito-junit-jupiter-3.3.3.jar;C:\Users\HONOR\.m2\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;C:\Users\HONOR\.m2\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-core\5.2.14.RELEASE\spring-core-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-jcl\5.2.14.RELEASE\spring-jcl-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\springframework\spring-test\5.2.14.RELEASE\spring-test-5.2.14.RELEASE.jar;C:\Users\HONOR\.m2\repository\org\xmlunit\xmlunit-core\2.7.0\xmlunit-core-2.7.0.jar;C:\Users\HONOR\.m2\repository\com\alibaba\fastjson\1.2.71\fastjson-1.2.71.jar;C:\Users\HONOR\.m2\repository\org\apache\commons\commons-lang3\3.10\commons-lang3-3.10.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 cn.itcast.hotel.HotelDemoApplicationTests,contextLoads
04-16 11:12:39.690 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [cn.itcast.hotel.HotelDemoApplicationTests], using SpringBootContextLoader
04-16 11:12:39.696 [main] INFO  o.s.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [cn.itcast.hotel.HotelDemoApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
04-16 11:12:39.696 [main] INFO  o.s.t.c.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [cn.itcast.hotel.HotelDemoApplicationTests]: HotelDemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
04-16 11:12:39.815 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration cn.itcast.hotel.HotelDemoApplication for test class cn.itcast.hotel.HotelDemoApplicationTests
04-16 11:12:39.944 [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.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]
04-16 11:12:39.964 [main] INFO  o.s.b.t.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@5cde6747, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@63a270c9, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@37c7595, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@3ed242a4, org.springframework.test.context.support.DirtiesContextTestExecutionListener@1199fe66, org.springframework.test.context.transaction.TransactionalTestExecutionListener@614df0a4, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@1fdf1c5, org.springframework.test.context.event.EventPublishingTestExecutionListener@2d96543c, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@73a2e526, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@7d64e326, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@13f95696, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@cd1d761, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@68be8808, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@32193bea]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.3.10.RELEASE)

04-16 11:12:40.245 [main] INFO  cn.itcast.hotel.HotelDemoApplicationTests - Starting HotelDemoApplicationTests on LAPTOP-2RMT4JS5 with PID 9364 (started by HONOR in D:\itcast\hotel-demo)
04-16 11:12:40.246 [main] DEBUG cn.itcast.hotel.HotelDemoApplicationTests - Running with Spring Boot v2.3.10.RELEASE, Spring v5.2.14.RELEASE
04-16 11:12:40.246 [main] INFO  cn.itcast.hotel.HotelDemoApplicationTests - No active profile set, falling back to default profiles: default
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.4.2 
04-16 11:12:42.394 [main] INFO  o.s.scheduling.concurrent.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
04-16 11:12:42.507 [main] INFO  o.s.b.a.web.servlet.WelcomePageHandlerMapping - Adding welcome page: class path resource [static/index.html]
04-16 11:12:42.766 [main] INFO  cn.itcast.hotel.HotelDemoApplicationTests - Started HotelDemoApplicationTests in 2.753 seconds (JVM running for 3.933)

java.lang.RuntimeException
	at cn.itcast.hotel.service.impl.HotelService.filters(HotelService.java:101)
	at cn.itcast.hotel.service.impl.HotelService$$FastClassBySpringCGLIB$$e419b4bb.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
	at cn.itcast.hotel.service.impl.HotelService$$EnhancerBySpringCGLIB$$aa63f09c.filters(<generated>)
	at cn.itcast.hotel.HotelDemoApplicationTests.contextLoads(HotelDemoApplicationTests.java:19)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

04-16 11:12:43.557 [SpringContextShutdownHook] INFO  o.s.scheduling.concurrent.ThreadPoolTaskExecutor - Shutting down ExecutorService 'applicationTaskExecutor'

进程已结束,退出代码-1

原因分析:

因为我之前也遇到过这个问题,总结了两点解决方案:

        ①检查mysql是否处于运行状态

        ②检查虚拟机是否联网(可能电缆被拔出而断网之类的)

 今天遇到的问题比较特殊,是前后端的交互没有做好。对于酒店星级,应该是startName.keyword,而不是starName


解决方案:

将starName替换为starName.keyword

    @Override
    public Map<String, List<String>> filters() {
        try {
            SearchRequest request = new SearchRequest("hotel");
            request.source().size(0);
            String[] arr = {"brandAgg", "cityAgg", "starAgg"};
            String[] fields = {"brand", "city", "starName.keyword"};
            for (int i = 0; i < arr.length; i++) {
                request.source().aggregation(AggregationBuilders
                        .terms(arr[i])
                        .field(fields[i])
                        .size(100)
                );
            }
            SearchResponse response = client.search(request, RequestOptions.DEFAULT);
            Aggregations aggregations = response.getAggregations();
            Map<String, List<String>> res = new HashMap<>();
            for (int i = 0; i < arr.length; i++) {
                List<String> brandList = new ArrayList<>();
                Terms arrTerms = aggregations.get(arr[i]);
                List<? extends Terms.Bucket> buckets = arrTerms.getBuckets();
                for (Terms.Bucket bucket : buckets) {
                    brandList.add(bucket.getKeyAsString());
                }
                res.put(fields[i], brandList);
            }
            return res;
        }catch (Exception e){
            throw new RuntimeException();
        }
    }

单元测试成功:

 

记录这篇回答,主要是想告诉大家遇到Neither @ContextConfiguration nor @ContextHierarchy found for test class这样的报错可能不是英文直译过来的问题,而是代码逻辑有问题,需要修改代码!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值