I'm trying to upgrade from Spring Boot 1.4 to 1.5.2. As far as I can tell I've followed the update guidelines.
There are actually two issues, the main one which is to do with embedded mongo:
EmbeddedServletContainerFactory now has to be explicitly created
In the test config class I've had to add this:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.setPort(port);
factory.setSessionTimeout(50, TimeUnit.MINUTES);
return factory;
}
I did not have to do this before. I had to include it because when I run a test it gives me this error:
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Embedded Mongo will not start
Now I get this error:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'embeddedMongoServer' available
No idea where I should be adding this bean (and indeed why I should be adding it)
My current setup
I have multiple tests that extend BaseIT, which starts like this:
@RunWith(SpringRunner.class)
@DataMongoTest
@SpringBootTest(classes = {TestConfig.class, TestMongoConfig.class},, webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT, value = "
{$server.port}")
@ActiveProfiles("test")
public abstract class BaseIT {...}
Mongo config class:
@Configuration
@EnableAutoConfiguration(exclude = { EmbeddedMongoAutoConfiguration.class })
@EnableMongoRepositories(basePackages = "...")
public class TestMongoConfig {
@Bean public MongoClient mongo(){...}
@Bean public MongodProcess mongodProcess(){...}
@Bean public MongodExecutable mongodExecutable(){...}
@Bean public IMongodConfig mongodConfig(){...}
@Bean public MongodStarter mongodStarter(){...}
}
Test config class:
@Configuration
@EnableAutoConfiguration(exclude = {EmbeddedMongoAutoConfiguration.class})
@ComponentScan(value = {...})
@EnableMongoRepositories(basePackages = {...)
@EnableWebMvc
public class TestConfig extends WebMvcConfigurerAdapter {...}