【问题标题】:Java Spring - Accessing Data with MongoDB execution errorJava Spring - 使用 MongoDB 执行错误访问数据
【发布时间】:2015-10-16 21:28:27
【问题描述】:

我想设置一个 Java Spring 和 MongoDB 的简单示例,但我还没有做到。在这种情况下,我遵循 Spring web 中的示例。

我已经使用 JRE8 安装了 Maven、Mongo DB 和 Java JDK 1.8。此外,在 pom.xml 文件中,由于编译错误,我不得不包含此依赖项:

    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-rest-core</artifactId>
    <version>2.3.1.RELEASE</version>
</dependency>

最后,按照上面提到的网页说明,我输入:

mvn spring-boot:run 要么 java -jar 目标/gs-accessing-data-mongodb-0.1.0.jar

在第一种情况下,spring-boot,我得到以下错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project gs-accessing-data-mongodb: An exception occured while running. null: InvocationTargetException: Error creating bean with name 'messageConverters' defined in class path resource [org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.web.HttpMessageConverters]: Factory method 'messageConverters' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException: com.fasterxml.jackson.core.JsonProcessingException -> [Help 1]

有什么想法吗?提前致谢。

【问题讨论】:

    标签: java spring mongodb maven


    【解决方案1】:

    它不起作用,我的依赖项如下所示:

       <dependencies>
        <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-core</artifactId>
        <version>2.3.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.0</version>
    </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-mongodb</artifactId>
            </dependency>
        </dependencies>
    

    控制台中的结果:

    Customers found with findAll():
    -------------------------------
    Customer[id=55b52943dac11e2ab8262f16, firstName='Alice', lastName='Smith']
    Customer[id=55b52944dac11e2ab8262f17, firstName='Bob', lastName='Smith']
    
    Customer found with findByFirstName('Alice'):
    --------------------------------
    Customer[id=55b52943dac11e2ab8262f16, firstName='Alice', lastName='Smith']
    Customers found with findByLastName('Smith'):
    --------------------------------
    Customer[id=55b52943dac11e2ab8262f16, firstName='Alice', lastName='Smith']
    Customer[id=55b52944dac11e2ab8262f17, firstName='Bob', lastName='Smith']
    2015-07-26 20:39:00.438  INFO 1884 --- [lication.main()] hello.Application                        : Started Application in 4.726 seconds (JVM running for 7.57)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多