FastDfs配置 导入已耐
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.1-RELEASE</version>
</dependency>
上传代码
package kit.pano.febs.web.controller;
import cn.hutool.http.HttpStatus;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import kit.pano.febs.common.domain.FebsResponse;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@RestController
@RequestMapping("/fast")
@Api(description = "上传图片工具类")
public class FastDfsUtilsController {
@Resource
private FastFileStorageClient fastFileStorageClient;
@ApiOperation("上传图片")
@PostMapping(value = "/uploadImage")
public FebsResponse uploadImage(@RequestParam("file") MultipartFile file) {
try {
StorePath storePath = this.fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(),
FilenameUtils.getExtension(file.getOriginalFilename()), null);
String url = storePath.getFullPath();
return new FebsResponse().code(HttpStatus.HTTP_OK).message("上传成功").data(url);
} catch (Exception e) {
e.printStackTrace();
}
return new FebsResponse().code(HttpStatus.HTTP_INTERNAL_ERROR).message("上传失败");
}
}
错误信息
Description:
A component required a bean of type 'com.github.tobato.fastdfs.service.FastFileStorageClient' that could not be found.
Action:
Consider defining a bean of type 'com.github.tobato.fastdfs.service.FastFileStorageClient' in your configuration.
解决方法:主类
SmsApplication中加入注解@Import(FdfsClientConfig.class)
继续出现错误
javax.management.InstanceAlreadyExistsException: MXBean already registered with name com.github.tobato.fastdfs.conn:type=FdfsConnectionPoolfdfsPool
如果换有错
推荐使用 : @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
注意:@EnableMBeanExport解决问题JMX重复注册问题,不要再配置 spring.jmx.enabled=false,以免影响SpringBoot默认的JMX监控。
最终Aoolication类注解如下
@SpringBootApplication
@EnableFeignClients
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
//@EnableCircuitBreaker
@EnableDistributedTransaction
public class TourismTenantApplication {
public static void main(String[] args) {
SpringApplication.run(TourismTenantApplication.class, args);
}
}