Fegin
2020-07-20 本文已影响0人
zjkdifvpwlkqumn
@Configuration
public class FeginConfiguration {
@Bean
public RequestInterceptor requestInterceptor() {
return requestTemplate -> {
String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();
if (sessionId != null) {
requestTemplate.header("Cookie", "SESSION=" + sessionId);
// security添加认证
try {
requestTemplate.header("authorization", String.format("Basic %s",
Base64.getEncoder().encodeToString(
String.format("%s:%s", "user", "password").getBytes("UTF-8"))));
} catch (UnsupportedEncodingException uee) {
LoggerUtil.error("<fegin-service>[error]" + uee.getMessage());
}
}
};
}
}