【问题标题】:SpringBoot and DynamoDb-Local EmbeddedSpring Boot 和 DynamoDb-Local Embedded
【发布时间】:2015-12-28 01:11:15
【问题描述】:

我有一个 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。有什么想法吗?

【问题讨论】:

  • 你能附上你的完整 POM 吗?或者,最好附加一个MCVE 以在本地复制它。
  • 运行mvn dependency:tree 看看你是否依赖jetty

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


【解决方案1】:

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

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

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

【讨论】:

  • 非常感谢您的回答,没想到是SpringBoot的一个bug :)
猜你喜欢
  • 2018-12-20
  • 2019-08-25
  • 2021-07-29
  • 1970-01-01
  • 2018-06-16
  • 2019-05-29
  • 2017-11-06
  • 2017-09-06
  • 1970-01-01
相关资源
最近更新 更多