Java 使用嵌入式MongoDb启动Spring引导时出现异常

Java 使用嵌入式MongoDb启动Spring引导时出现异常,java,mongodb,spring-boot,mongodb-java,Java,Mongodb,Spring Boot,Mongodb Java,我正在尝试在我的应用程序中使用嵌入式mongo db+springboot compile 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.7.RELEASE' compile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.50.5' compile 'cz.jirutka.spring:embedmongo-spring:1.3.1' Mongoconfig文件如

我正在尝试在我的应用程序中使用嵌入式mongo db+springboot

compile 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.7.RELEASE'
compile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.50.5'
compile 'cz.jirutka.spring:embedmongo-spring:1.3.1'
Mongoconfig文件如下所示

@Configuration
 public class MongoConfig {
            private static final String MONGO_DB_URL = "localhost";
            private static final String MONGO_DB_NAME = "sample_embeded_db";

        @Bean
        public MongoTemplate mongoTemplate() throws IOException {
            EmbeddedMongoFactoryBean mongo = new EmbeddedMongoFactoryBean();
            mongo.setBindIp(MONGO_DB_URL);
            MongoClient mongoClient = mongo.getObject();
            MongoTemplate mongoTemplate = new MongoTemplate(mongoClient, MONGO_DB_NAME);
            return mongoTemplate;
        }
    }
当我启动服务时,我得到以下错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$ApplicationWebSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setContentNegotationStrategy(org.springframework.web.accept.ContentNegotiationStrategy); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.setConfigurers(java.util.List); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.io.ResourceLoader org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.resourceLoader; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gridFsTemplate' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.data.mongodb.core.MongoTemplate]: : Error creating bean with name 'mongoTemplate' defined in class path resource [org/techie/MongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: File C:\Users\Raj\.embedmongo\win32\mongodb-win32-x86_64-3.2.1.zip; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/techie/MongoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is de.flapdoodle.embed.process.exceptions.DistributionException: java.io.IOException: File C:\Users\Raj\.embedmongo\win32\mongodb-win32-x86_64-3.2.1.zip
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1012)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
..........
Caused by: java.util.zip.ZipException: archive is not a ZIP archive
at org.apache.commons.compress.archivers.zip.ZipFile.positionAtEndOfCentralDirectoryRecord(ZipFile.java:847)
at org.apache.commons.compress.archivers.zip.ZipFile.positionAtCentralDirectory(ZipFile.java:777)
at org.apache.commons.compress.archivers.zip.ZipFile.populateFromCentralDirectory(ZipFile.java:522)
at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:216)
at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:192)
原因:org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连线方法:public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.SetFilterChainProxy SecurityConfigure(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List)抛出java.lang.Exception;嵌套异常为org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$ApplicationWebsecurityConfigureAdapter”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接方法:public void org.springframework.security.config.annotation.web.configuration.websecurityConfigureAdapter.setContentNegotionStrategy(org.springframework.web.accept.ContentNegotionStrategy);嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.beancreatitionException:无法自动连接方法:public void org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.setConfigurers(java.util.List);嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接字段:private org.springframework.core.io.ResourceLoader org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.ResourceLoader;嵌套异常为org.springframework.beans.factory.unsatifiedDependencyException:创建名为“gridFsTemplate”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]中定义:未满足的依赖项通过索引为1的构造函数参数表示[org.springframework.data.mongodb.core.MongoTemplate]::使用类路径资源[org/techie/MongoConfig.class]中定义的名称“MongoTemplate”创建bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.bean实例化异常:未能实例化[org.springframework.data.mongodb.core.MongoTemplate]:工厂方法“mongoTemplate”引发异常;嵌套异常为de.flapdoodle.embed.process.exceptions.DistributionException:java.io.IOException:文件C:\Users\Raj\.embedmongo\win32\mongodb-win32-x8664-3.2.1.zip;嵌套异常为org.springframework.beans.Factory.BeanCreationException:创建名为“mongoTemplate”的bean时出错类路径资源[org/techie/MongoConfig.class]:通过工厂方法实例化Bean失败;嵌套异常为org.springframework.beans.BeanInstantiationException:实例化[org.springframework.data.mongodb.core.MongoTemplate]失败:工厂方法“mongoTemplate”引发异常;嵌套异常为de.flapdoodle.embed.process.exceptions.DistributionException:java.io.IOException:文件C:\Users\Raj\.embeddMongo\win32\mongodb-win32-x86_64-3.2.1.zip
位于org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor.postProcessPropertyValues(AutoWiredNotationBeanPostProcessor.java:334)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
位于org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:368)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1117)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1012)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
..........
原因:java.util.zip.ZipException:存档不是zip存档
在org.apache.commons.compress.arc上
compile 'org.springframework.boot:spring-boot-starter-data-mongodb:1.3.1.RELEASE'