为什么我的fladoodle Embedded MongoDB 测试无法运行?(创建 'embeddedMongoServer' 无法启动进程 EOF) [英] Why does my flapdoodle Embedded MongoDB test fail to run? (creating 'embeddedMongoServer' could not start process EOF)

查看:198
本文介绍了为什么我的fladoodle Embedded MongoDB 测试无法运行?(创建 'embeddedMongoServer' 无法启动进程 EOF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法构建我的全新项目.我使用 https://start.spring.io/ 来生成一个全新的 Spring 2.0 MongoDB Maven 项目,并且我想要一个嵌入式 MongoDB 数据库用于我的集成测试.spring 初始值设定项为此添加了 de.flapdoodle.embed.mongo 的依赖项.

I'm having trouble getting my brand new project to build. I used https://start.spring.io/ to generate a fresh new Spring 2.0 MongoDB Maven project, and I want to have an embedded MongoDB database for my integration tests. The spring initializer added a dependency for de.flapdoodle.embed.mongo to that end.

但是每次我尝试运行mvn clean package"时,我在测试过程中都会收到以下错误:

But every time I try to run a "mvn clean package", I get the following error during my test:

Caused by: org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'embeddedMongoServer' defined in class path resource
[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: 
Invocation of init method failed; nested exception is java.io.IOException: 
Could not start process: <EOF>
at de.flapdoodle.embed.mongo.AbstractMongoProcess.onAfterProcessStart(AbstractMongoProcess.java:79) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.AbstractProcess.<init>(AbstractProcess.java:116) ~[de.flapdoodle.embed.process-2.0.2.jar:na]
at de.flapdoodle.embed.mongo.AbstractMongoProcess.<init>(AbstractMongoProcess.java:53) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodProcess.<init>(MongodProcess.java:50) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:44) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.mongo.MongodExecutable.start(MongodExecutable.java:34) ~[de.flapdoodle.embed.mongo-2.0.3.jar:na]
at de.flapdoodle.embed.process.runtime.Executable.start(Executable.java:108) ~[de.flapdoodle.embed.process-2.0.2.jar:na]

我错过了什么?

我的应用程序文件非常简单:

My Application file is pretty straightforward:

@SpringBootApplication
public class NewnewinternetApplication {

    public static void main(String[] args) {
        SpringApplication.run(NewnewinternetApplication.class, args);
    }
}

我的配置文件很简单:

@Configuration
@EnableMongoRepositories
@ComponentScan(basePackages = "com.snoop.dougg.newnewinternet")
public class AppConfig {

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/");
        resolver.setSuffix(".html");
        return resolver;
    }
}

我有两个简单的控制器,目前只返回静态输出.

I have two simple controllers returning just static output for now.

我有一个小文件:

@Document(collection = "user")
public class User implements Serializable {
    protected static final long serialVersionUID = -1L;

    @Id
    private String id;

    private String username;
    private String firstName;
    private String lastName;

    public User() {}

    public User(String username, String firstName, String lastName) {
        this.username = username;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    //Getters, setters, and equals and hash code methods...
}

然后是一个愚蠢的小测试:

And then a silly little test:

@RunWith(SpringRunner.class)
//@SpringBootTest -> Doesn't work either
@DataMongoTest
public class NewnewinternetApplicationTests {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Test
    public void sillyLittleTest() {
        mongoTemplate.save(new User("sdoug", "Snoop", "Dougg"));
        Assert.notNull(
            mongoTemplate.find(
                new Query(Criteria.where("firstName").is("Snoop")), User.class),
            "Couldn't find by first name!");
    }
}

然后是我的 pom 文件,我真的只是一个人留下:

And then my pom file, which I really just left alone:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.snoop.dougg.newnewinternet</groupId>
    <artifactId>NewNewInternet</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>NewNewInternet</name>
    <description>A new new internet</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <azure.version>2.0.1</azure.version>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.M9</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-active-directory-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-spring-boot</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-spring-boot-bom</artifactId>
                <version>${azure.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>


</project>

推荐答案

注释掉 application.properties 中的以下几行并将它们放在不同的配置文件中也可以.我在这里找到了它>

Commenting out the following lines in application.properties and placing them in a different profile can also work. I found it here

spring.data.mongodb.database=
spring.data.mongodb.host=
spring.data.mongodb.port=

这篇关于为什么我的fladoodle Embedded MongoDB 测试无法运行?(创建 'embeddedMongoServer' 无法启动进程 EOF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆