Spring boot Maven install error - Unable to find a @SpringBootConfiguration

Viewed 559

I'm trying to do clean and install on my Spring Boot project in before creating the Jar file for my project however I came across this error

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

I'm new to Spring Boot and have never really utilized the test function of it. So my test class is pretty much default of how it was initially created with the project.

My test class

   package com.Alex.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;


@SpringBootTest
class WebAppApplicationTests {

    @Test
    void contextLoads() {
    }

}

File directory

enter image description here

3 Answers

@RunWith(SpringRunner.class) works

For your test class, you should add:

    @RunWith(SpringRunner.class)

Also, you should consider change your annotation for test like this:

    @SpringBootTest(classes = { WebAppApplication.class })

where Application.class is the main class of your spring boot project

As problem also that not able to find your springboot configuration for test method written. First of all the method mentioned in the class needs to be public.

@Test
public void contextLoads() {
}

It will work with assuming this to be your test of main class as mention "WebAppApplication", also run test with @RunWith(SpringRunner.class) mentioned.

Related