老师这个错误怎么办java.lang.IllegalStateException: Unable to find

来源:3-3 -编写程序代码及测试用例

慕娘9557946

2017-09-19

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test


at org.springframework.util.Assert.state(Assert.java:70)

at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:173)

at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:133)

at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:409)

at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildDefaultMergedContextConfiguration(AbstractTestContextBootstrapper.java:323)

at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:277)

at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:112)

at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.buildTestContext(SpringBootTestContextBootstrapper.java:78)

at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:120)

at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)

at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)

at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)

at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)

at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)

at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)



http://szimg.mukewang.com/59c0d8260001fe2911620630.jpg

http://szimg.mukewang.com/59c0d98e0001ff9210360587.jpg


网上说是测试类的位置不对 我放到cn.xxx.spring.boot.myblog.initializerstart

测试可以运行 但报404 是我的string( )没有equlsto方法. 

写回答

2回答

老卫

2017-09-19

Application 类,应该是处于项目的根目录。请对照课程,调整项目的结构。

0
0

慕娘9557946

提问者

2017-09-19

只学过spring 第一次学spring boot 要哭了,,终于弄好了  小伙伴们一定要注意老师的路径. 

controller与 Application的路径 老师可以讲解一下么. 为什么会这样呢.


//szimg.mukewang.com/59c0de2c0001fa1904290546.jpg



0
1
老卫
原理很简单,就是 Application 类,上面的注解,就是启用了 Spring 中的扫包注入的机制,即按照约定, Application 类下的节点中的 Bean 可以被自动注入。 请遵循“约定大约配置”
2017-09-19
共1条回复

基于Spring Boot技术栈博客系统企业级前后端实战

毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap

1296 学习 · 738 问题

查看课程