SpringBoot 和 DynamoDb-Local Embedded

Dan*_*zyk 6 java junit unit-testing amazon-dynamodb spring-boot

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

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>DynamoDBLocal</artifactId>
    <version>1.10.5.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

And*_*son 5

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

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

@Bean
public EmbeddedServletContainerFactory tomcatContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory();
}
Run Code Online (Sandbox Code Playgroud)