zoukankan      html  css  js  c++  java
  • Unsatisfied dependency expressed through field 'mongoTemplate'

    具体情况是我的聚合项目,在使用

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-mongodb</artifactId>
               <!– <version>2.1.5.RELEASE</version>–>
            </dependency>
    

    遇到报错,大概就是连接linux 在一段时间,大概8分钟左右,会自动断开,下次第一次刷新会报错,之后就会好了

    2020-06-28 10:06:55.058  WARN 25076 --- [nio-9080-exec-2] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:8, serverValue:5252}] to 112.124.46.197:22017. All connections to 112.124.46.197:22017 will be closed.
    2020-06-28 10:06:55.058  INFO 25076 --- [nio-9080-exec-2] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:8, serverValue:5252}] to 112.124.46.197:22017 because there was a socket exception raised by this connection.
    org.springframework.data.mongodb.UncategorizedMongoDbException: Exception sending message; nested exception is com.mongodb.MongoSocketWriteException: Exception sending message
    	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
    	at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2774)
    

     自己创建一个demo ,使用的高版本后,并没有此问题,可是老项目中,主依赖中我修改了mongodb的版本,问题依然存在,讲mongodb单纯分出一个项目后,这个问题可以解决.

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

    于是只能单独将mongo分出来了,在主项目中引入配置文件

     此时启动会遇到问题:

    Unsatisfied dependency expressed through field 'mongoTemplate'

    疑惑,测试的demo里面也是这样写的,没有出现此问题,为何迁移到主项目中mongotemplate没有注入

    原因:

    去掉主项目的启动类中的两个mongoauto配置,就解决了这个问题.

  • 相关阅读:
    [译]《Sphinx权威指南》
    sphinx 配置文件全解析
    利用 crontab 來做 Linux 固定排程
    http协议中用于上传多个文件的 multipart 字段
    Python 代码覆盖率统计工具 coverage.py
    Disruptor 基础篇
    NPM:常用命令的生命周期脚本
    十大经典排序算法(动图演示)【转】
    TypeScript Jest 调试
    NPM: 日常开发环境配置
  • 原文地址:https://www.cnblogs.com/sunxun/p/13206563.html
Copyright © 2011-2022 走看看