zoukankan      html  css  js  c++  java
  • com.aliyun.oss.ClientException: Connection error due to: Connection pool shut down

    com.aliyun.oss.ClientException: Connection error due to: Connection pool shut down
    [ErrorCode]: Unknown
    [RequestId]: Unknown


    原因:如果你使用的spring的注入方式,那么所获取的OSS是一个单例对象。
    当使用ossClient.shutdown()时,下一次请求将无法获取连接。

    Spring单例对象注入

    1     @Bean
    2     public OSS ossClient() {
    3         return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    4     }


    解决方案:使用多例注入@Scope("prototype"),或者直接 new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret)

    1     @Bean
    2     @Scope("prototype")
    3     public OSS ossClient() {
    4 //        return new OSSClient(endpoint, accessKeyId, accessKeySecret);
    5         return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    6     }


    获取OSS对象,可以定义一个方法单独返回。那么每一次调用这个方法都会产生一个新的对象。

    1     /**
    2      * 获取ossClient对象(多例)
    3      * 由于使用完成需要关闭,所以需要创建多例的ossClient对象
    4      */
    5     private OSS getOssClient(){
    6         return ossConfiguration.ossClient();
    7     }
  • 相关阅读:
    前端js(一)
    前端CSS
    前端HTML
    视图等
    Navicat使用
    查询语句
    SpringBoot不能直接访问templates下的静态资源
    Mybatis什么时候用${}
    thymeleaf使用restul风格URL
    SpringBoot使用PageHelper
  • 原文地址:https://www.cnblogs.com/IT-study/p/11358832.html
Copyright © 2011-2022 走看看