Without going into excruciating detail, I am having an issue when I run my Junit tests all at once. If I run them class by class, everything is great! Otherwise I have trouble because I cannot restart my WebApplication inbetween junit-test-class. This causes me to have Zookeeper server clients in my WebApplication that hang around after I go through the shutdown and startup of the Zookeeper server in-between classes. Those Zookeeper server clients can take a while to resync with server and this causes unpredictable behavior...
Is there a way to have my SpringBootServletInitializer class restart by calling something in the @BeforeClass and @AfterClass methods of a JUnit test?
WebApplication.java
@ComponentScan
@EnableAutoConfiguration
@EnableWebMvc
@EnableHyperMediaSupport(...)
@PropertySources(...)
public class WebApplication extends SpringBootServletInitializer
{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(WebApplication.class);
}
@Override
protected WebApplicationContext run(SpringApplication application)
{
application.getSources().remove(ErrorPageFilter.class);
return (WebApplicationContext) application.run();
}
public static void main(String[] args)
{
SpringApplication.run(WebApplication.class, args);
}
}
@DirtiesContext
? docs.spring.io/spring/docs/current/javadoc-api/org/… – Lula