当前位置:   article > 正文

springboot中集成fastDFS_max-total-per-key

max-total-per-key

springboot中集成fastDFS 分布式文件存储系统

1、 pom.xml中引入

  1. <dependency>
  2. <groupId>com.github.tobato</groupId>
  3. <artifactId>fastdfs-client</artifactId>
  4. <version>1.27.2</version>
  5. </dependency>

2、 application.yml中配置

  1. spring:
  2. application:
  3. name: ssdemo
  4. servlet:
  5. multipart:
  6. max-file-size: 20MB
  7. max-request-size: 20MB
  8. fdfs:
  9. so-timeout: 1500 # socket连接超时时间
  10. connect-timeout: 6000 # 连接tracker超时时间
  11. thumb-image: #缩略图生成参数 ,可选
  12. width: 150
  13. height: 150
  14. tracker-list: #TrackerList参数,支持多个
  15. - 192.168.11.41:22122
  16. pool:
  17. #从池中借出的对象的最大数目(配置为-1表示不限制)
  18. max-total: -1
  19. #获取连接时的最大等待毫秒数,默认值5000
  20. max-wait-millis: 5000 #
  21. #每个key最大连接数
  22. max-total-per-key: 50
  23. #每个key对应的连接池最大空闲连接数
  24. max-idle-per-key: 10
  25. #每个key对应的连接池最小空闲连接数
  26. max_idle_per_key: 5

3、FastDFSConfig.java 配置类

  1. package cn.cbyzs.ssdemo.config;
  2. import com.github.tobato.fastdfs.FdfsClientConfig;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.context.annotation.EnableMBeanExport;
  5. import org.springframework.context.annotation.Import;
  6. import org.springframework.jmx.support.RegistrationPolicy;
  7. @Configuration
  8. @Import(FdfsClientConfig.class) // 导入FastDFS-Client组件
  9. @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) // 解决jmx重复注册bean的问题
  10. public class FastDFSConfig {
  11. }

4、Fdfs的上传controller

  1. package cn.cbyzs.ssdemo.other.controller;
  2. import cn.cbyzs.ssdemo.common.RetMsg;
  3. import cn.cbyzs.ssdemo.common.fastDFS.FastDFSClientUtil;
  4. import cn.cbyzs.ssdemo.common.jwt.JwtTokenIgnore;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestParam;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import org.springframework.web.multipart.MultipartFile;
  10. @RestController
  11. @RequestMapping("/fdfs")
  12. public class FdfsController {
  13. @Autowired
  14. private FastDFSClientUtil fastDFSClientUtil;
  15. @JwtTokenIgnore
  16. @RequestMapping("/upload")
  17. public RetMsg upload(@RequestParam(value = "file",required = false)
  18. MultipartFile file){
  19. //调用 fdfsClient的上传接口
  20. String path =fastDFSClientUtil.uploadFile(file);
  21. return RetMsg.success(path);
  22. }
  23. }

测试上传 ,用postman调用controller层接口,上传一个图片成功 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/169893
推荐阅读
相关标签
  

闽ICP备14008679号