feign 의 url 에 get 인 자 를 추가 하여 검사 기능 을 실현 합 니 다.
http 클 라 이언 트 대신 feign 을 사용 하여 http 대 리 를 생 성 할 때 url 마다 검사 서명 의 세 가지 인 자 를 추가 해 야 합 니 다. 예 를 들 어 appkey, sign, 시간 스탬프 등 입 니 다. 작성 방법 은 다음 과 같 습 니 다.
@FeignClient(url = "${url}/xxx",name = "xxxFeign")
이루어지다
1 클래스 계승 feign. client. Default 를 쓰 고 execute 방법 을 다시 씁 니 다.
import com.js.apiserver.util.endecryption.MD5Util;
import feign.Client;
import feign.Request;
import feign.Response;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException;
public class MyDefaultClient extends Client.Default {
@Value("${app_key}")
private String app_key;
@Value("${app_secret}")
private String app_secret;
public MyDefaultClient() {
super(null, null);
}
@Override
public Response execute(Request request, Request.Options options) throws IOException {
String timestamp = String.valueOf(System.currentTimeMillis());
// SIGN
String sign = MD5Util.encrypByMd5Jar(timestamp + "#" + app_secret);
String url = request.url()+"?timestamp="+timestamp+"&app_key="+app_key+"&sign="+sign;
return super.execute(Request.create(request.httpMethod(),url,request.headers(),request.requestBody()), options);
}
}
2. 설정 클래스 를 작성 합 니 다.
import feign.Client;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
@Configuration
public class JsFeignClientAutoConfiguration {
@Autowired
private ObjectFactory messageConverters;
@ConditionalOnMissingBean(name = "myHttpClient")
@Bean("myHttpClient")
@Primary
@ConditionalOnProperty("app_key")
public Client setClient(){
return new MyDefaultClient();
}
@Bean
@Primary
@Scope("prototype")
public Encoder multipartFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
@Bean
@Primary
public feign.Logger.Level multipartLoggerLevel() {
return feign.Logger.Level.FULL;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[MeU] Hashtag 기능 개발➡️ 기존 Tag 테이블에 존재하지 않는 해시태그라면 Tag , tagPostMapping 테이블에 모두 추가 ➡️ 기존에 존재하는 해시태그라면, tagPostMapping 테이블에만 추가 이후에 개발할 태그 기반 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.