gpt4 book ai didi

java - SpringBoot 和 DynamoDb-Local Embedded

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:31 24 4
gpt4 key购买 nike

我有一个 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

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

最佳答案

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

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

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

关于java - SpringBoot 和 DynamoDb-Local Embedded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32862876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com