Error: Unable to find @SpringBootConfiguration when doing @WebMvcTest for Spring Controller

前端 未结 4 892
别那么骄傲
别那么骄傲 2020-12-13 17:57

I am testing my controller given below

@Controller
public class MasterController {

@GetMapping(\"/\")
public String goLoginPage(){
    return \"index\";
}
}         


        
4条回答
  •  天涯浪人
    2020-12-13 18:25

    I had the same error, and found that when I had generated the project my pom.xml showed my groupId as com.example rather than with my actual domain:
    com.example
    I corrected the pom.xml to be:
    com.mydomain
    Next, I changed the file structure from:
    src/test/java/com/example to src/test/java/com/mydomain
    Last, I had to update the package declaration inside my
    SampleProjectApplicationTest.java
    file to match the correct file structure. Once that was all in place, the tests worked fine.

    I am not sure how I ended up with com.example where the rest of my project was correct, but the fix was that simple in my case.

    Hopefully this helps someone.

提交回复
热议问题