简体   繁体   English

SpringBoot和DynamoDb-Local Embedded

[英]SpringBoot and DynamoDb-Local Embedded

I have a spring-boot (1.2.6) webapp. 我有一个spring-boot(1.2.6)webapp。 I use DynamoDb as an event store for the app. 我使用DynamoDb作为应用程序的事件存储。 In my integration tests I would like to use this approach to start up DynamoDb-Local from my integration test code. 在我的集成测试中,我想使用这种方法从我的集成测试代码启动DynamoDb-Local。
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). 我甚至没有在集成测试中添加任何代码,我只是将repo和依赖项添加到我的POM中(如上面链接的AWS论坛公告中所述)。 Without this dependency everything runs just fine. 没有这种依赖,一切都运行得很好。 I can attach my POM if needed. 如果需要,我可以附上我的POM。 Any ideas? 有任何想法吗?

com.amazonaws:DynamoDBLocal depends on some of Jetty. com.amazonaws:DynamoDBLocal依赖于某些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. Jetty在类路径上的存在让Spring Boot误以为你想要使用Jetty,即使它所需的Jetty的所有部分都不可用。 This is a bug in Spring Boot. 这是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: 在此期间,您可以通过向应用程序添加一个明确告诉Spring Boot您要使用Tomcat的bean来解决此问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM