SpringBoot和DynamoDb-Local Embedded

时间:2015-09-30 09:43:05

标签: java unit-testing junit spring-boot amazon-dynamodb

我有一个spring-boot(1.2.6)webapp。我使用DynamoDb作为应用程序的事件存储。在我的集成测试中,我想使用this approach从我的集成测试代码中启动DynamoDb-Local。 但是,在包含依赖项之后:

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

运行集成测试时会出现以下错误:

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

我甚至没有在我的集成测试中添加任何代码,我只是将repo和依赖项添加到我的POM中(如上面链接的AWS论坛公告中所述)。没有这种依赖,一切都运行得很好。如果需要,我可以附上我的POM。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

com.amazonaws:DynamoDBLocal取决于Jetty的某些内容。 Jetty在类路径上的存在让Spring Boot误以为你想要使用Jetty,即使它所需的Jetty的所有部分都不可用。这是Spring Boot中的一个错误。感谢您告诉我们。我已经打开了an issue,以便我们可以修复它。

与此同时,您可以通过向应用程序添加一个明确告诉Spring Boot您要使用Tomcat的bean来解决此问题:

@Bean
public EmbeddedServletContainerFactory tomcatContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory();
}