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配置,就解决了这个问题.

  • 相关阅读:
    win7(windows 7)系统下安装SQL2005(SQL Server 2005)图文教程
    Jenkins 不同角色不同视图及不同权限设置
    dig挖出DNS的秘密
    Linux Shell高级技巧
    《Linux内核设计与实现》读书笔记
    github开发
    NodeJs-- 新建项目实例
    Linux makefile 教程 非常详细,且易懂
    cms完整视频教程+源码 孔浩老师 全131讲
    Redis实现简单消息队列
  • 原文地址:https://www.cnblogs.com/sunxun/p/13206563.html
Copyright © 2011-2022 走看看