S
S
sur-pavel2020-07-06 13:40:46
Spring
sur-pavel, 2020-07-06 13:40:46

How to add a ServletWebServerFactory bean?

There is a test:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { ProjectRepository.class, ProjectController.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class ProjectRestControllerIntegrationTest {

    @Bean 
    ServletWebServerFactory servletWebServerFactory(){
    return new TomcatServletWebServerFactory();
    }
    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private ProjectRepository projectRepository;

    @Autowired
    private ProjectController projectController;

    @Test
    public void contexLoads() throws Exception {

        assertThat(projectRepository).isNotNull();
        assertThat(projectController).isNotNull();
    }


which throws the error: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sur-pavel, 2020-07-06
@sur-pavel

Forgot to add SpringBootApplication.class to @SpringBootTest )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question