Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot and DynamoDb-Local Embedded

I have a spring-boot (1.2.6) webapp. I use DynamoDb as an event store for the app. In my integration tests I would like to use this approach to start up DynamoDb-Local from my integration test code.
However, after including the dependency:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>DynamoDBLocal</artifactId>
    <version>1.10.5.1</version>
</dependency>

I will get the following error when running integration test:

java.lang.IllegalStateException: Failed to load ApplicationContext
(....)
Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jettyEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedJetty.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'jettyEmbeddedServletContainerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext
(....)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jettyEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedJetty.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'jettyEmbeddedServletContainerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext
(....)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'jettyEmbeddedServletContainerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext
(....)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext
(....)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.webapp.WebAppContext

I did not even add any code to my integration test, I literally just added the repo and dependency to my POM (as described in the AWS forum announcement linked above). Without this dependency everything runs just fine. I can attach my POM if needed. Any ideas?

like image 309
Daniel Gruszczyk Avatar asked Sep 30 '15 09:09

Daniel Gruszczyk


1 Answers

com.amazonaws:DynamoDBLocal depends on some of Jetty. Jetty's presence on the classpath is confusing Spring Boot into thinking that you want to use Jetty, even though all of the parts of Jetty that it needs aren't available. This is a bug in Spring Boot. Thanks for letting us know about it. I've opened an issue so that we can fix it.

In the meantime, you can work around the problem by adding a bean to your application that explicitly tells Spring Boot that you want to use Tomcat:

@Bean
public EmbeddedServletContainerFactory tomcatContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory();
}
like image 169
Andy Wilkinson Avatar answered Sep 19 '22 07:09

Andy Wilkinson