feat(oss): 实现文件上传功能并集成Feign调用
- 新增文件上传接口,支持multipart/form-data格式 - 配置Spring Servlet multipart参数,设置文件大小限制 - 添加Feign客户端配置,支持表单提交 - 实现Feign请求拦截器,传递用户上下文信息 - 创建OSS服务API接口,用于文件上传 - 在用户服务中集成OSS RPC调用,实现头像和背景图上传 - 添加上传失败的业务异常处理 - 更新pom.xml依赖,引入OpenFeign、负载均衡及Feign表单相关组件 - 定义API常量和服务名称 - 启用Feign客户端扫描,支持跨服务调用
This commit is contained in:
@@ -43,6 +43,9 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.hanserwei.framework.biz.context.config;
|
||||
|
||||
import com.hanserwei.framework.biz.context.interceptor.FeignRequestInterceptor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@AutoConfiguration
|
||||
public class FeignContextAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public FeignRequestInterceptor feignRequestInterceptor() {
|
||||
return new FeignRequestInterceptor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hanserwei.framework.biz.context.interceptor;
|
||||
|
||||
import com.hanserwei.framework.biz.context.holder.LoginUserContextHolder;
|
||||
import com.hanserwei.framework.common.constant.GlobalConstants;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class FeignRequestInterceptor implements RequestInterceptor {
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
// 获取当前上下文中的用户 ID
|
||||
Long userId = LoginUserContextHolder.getUserId();
|
||||
|
||||
// 若不为空,则添加到请求头中
|
||||
if (Objects.nonNull(userId)) {
|
||||
requestTemplate.header(GlobalConstants.USER_ID, String.valueOf(userId));
|
||||
log.info("########## feign 请求设置请求头 userId: {}", userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
com.hanserwei.framework.biz.context.config.ContextAutoConfiguration
|
||||
com.hanserwei.framework.biz.context.config.ContextAutoConfiguration
|
||||
com.hanserwei.framework.biz.context.config.FeignContextAutoConfiguration
|
||||
Reference in New Issue
Block a user