mardi 4 octobre 2016

@SpringBootTest for a non-spring-boot application

I am creating a non-spring-boot application using spring-rest, spring-data-jpa etc and I would like to do integration testing using spring boot (1.4.1.RELEASE). Note that I don't have a SpringApplication class or @SpringApplication annotation anywhere

On my test class I have

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MyConfiguration.class)
public class MyIT { }

@RestController
public class MyController { }

This is starting an embedded tomcat and I can see that my controller is being initialized, however, I get a 404 when calling my service using TestRestTemplate. It appears that DispatcherServlet does not seem to know about my controllers

Also, I had to define a servletContainer bean as follows

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(9000);
    factory.setSessionTimeout(10, TimeUnit.MINUTES);
    return factory;
}

Aucun commentaire:

Enregistrer un commentaire