|
|
@@ -1,27 +1,27 @@
|
|
|
-package com.jzg.openfeign.config;
|
|
|
-
|
|
|
-import feign.RequestInterceptor;
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.web.context.request.RequestAttributes;
|
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
-
|
|
|
-@Configuration
|
|
|
-public class FeignConfig {
|
|
|
- @Bean
|
|
|
- public RequestInterceptor requestInterceptor() {
|
|
|
- //拦截器 设置Token
|
|
|
- return requestTemplate -> {
|
|
|
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
- if (requestAttributes instanceof ServletRequestAttributes) {
|
|
|
- HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
|
|
|
- String token = request.getHeader("Authorization");
|
|
|
- if (token != null) {
|
|
|
- requestTemplate.header("Authorization", token);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.jzg.openfeign.config;
|
|
|
+//
|
|
|
+//import feign.RequestInterceptor;
|
|
|
+//import jakarta.servlet.http.HttpServletRequest;
|
|
|
+//import org.springframework.context.annotation.Bean;
|
|
|
+//import org.springframework.context.annotation.Configuration;
|
|
|
+//import org.springframework.web.context.request.RequestAttributes;
|
|
|
+//import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+//import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+//
|
|
|
+//@Configuration
|
|
|
+//public class FeignConfig {
|
|
|
+// @Bean
|
|
|
+// public RequestInterceptor requestInterceptor() {
|
|
|
+// //拦截器 设置Token
|
|
|
+// return requestTemplate -> {
|
|
|
+// RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
+// if (requestAttributes instanceof ServletRequestAttributes) {
|
|
|
+// HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
|
|
|
+// String token = request.getHeader("Authorization");
|
|
|
+// if (token != null) {
|
|
|
+// requestTemplate.header("Authorization", token);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// };
|
|
|
+// }
|
|
|
+//}
|