fix(文件服务): 修复无法获取到文件服务的异常
This commit is contained in:
@@ -2,6 +2,7 @@ package cn.celess.blog.service.interfaces;
|
||||
|
||||
import cn.celess.blog.entity.model.QiniuResponse;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -10,6 +11,7 @@ import java.io.InputStream;
|
||||
* @date : 2020/10/15 18:19
|
||||
* @desc : 文件管理器 定义操作文件的方法
|
||||
*/
|
||||
@Service
|
||||
public interface FileManager {
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.celess.blog.service.interfaces;
|
||||
|
||||
import cn.celess.blog.entity.model.QiniuResponse;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -10,7 +11,8 @@ import java.io.InputStream;
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
@Service("fileService")
|
||||
@FunctionalInterface
|
||||
public interface FileService {
|
||||
/**
|
||||
* 获取文件管理器
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.celess.blog.service.serviceimpl;
|
||||
|
||||
import cn.celess.blog.service.interfaces.FileManager;
|
||||
import cn.celess.blog.service.interfaces.FileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/10/15 18:52
|
||||
* @desc :
|
||||
*/
|
||||
@Service("fileServiceImpl")
|
||||
public class FileServiceImpl implements FileService {
|
||||
@Resource(name = "qiniuFileServiceImpl")
|
||||
FileManager qiniuFileManager;
|
||||
|
||||
@Override
|
||||
public FileManager getFileManager() {
|
||||
return qiniuFileManager;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import java.io.InputStream;
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
@Service("qiniuFileServiceImpl")
|
||||
public class QiniuFileServiceImpl implements FileManager {
|
||||
private static final Configuration cfg = new Configuration(Zone.zone2());
|
||||
private static UploadManager uploadManager;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.beans.Transient;
|
||||
import java.io.InputStream;
|
||||
@@ -45,7 +46,7 @@ public class UserServiceImpl implements UserService {
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
@Resource(name = "fileServiceImpl")
|
||||
FileService fileService;
|
||||
@Autowired
|
||||
RedisUtil redisUtil;
|
||||
|
||||
@@ -9,6 +9,8 @@ import cn.celess.blog.entity.request.LoginReq;
|
||||
import cn.celess.blog.entity.request.UserReq;
|
||||
import cn.celess.blog.mapper.UserMapper;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.service.interfaces.FileManager;
|
||||
import cn.celess.blog.service.interfaces.FileService;
|
||||
import cn.celess.blog.util.MD5Util;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
@@ -116,7 +118,7 @@ public class UserControllerTest extends BaseTest {
|
||||
|
||||
// mock 实现类
|
||||
// FIXME :: mock 时不应该为 qiniuService
|
||||
mockInjectInstance(userService, "qiniuService", new TestQiniuFileServiceImpl());
|
||||
mockInjectInstance(userService, "fileService", (FileService) TestQiniuFileServiceImpl::new);
|
||||
|
||||
MockMultipartFile file = new MockMultipartFile("file", "logo.png", MediaType.IMAGE_PNG_VALUE, inputStream);
|
||||
getMockData(multipart("/user/imgUpload").file(file), userLogin()).andDo(result -> {
|
||||
|
||||
Reference in New Issue
Block a user