本文整理匯總了Java中org.springframework.cloud.netflix.feign.FeignClient類的典型用法代碼示例。如果您正苦於以下問題:Java FeignClient類的具體用法?Java FeignClient怎麽用?Java FeignClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FeignClient類屬於org.springframework.cloud.netflix.feign包,在下文中一共展示了FeignClient類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: after
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
/**
* @param data
* @throws ClassNotFoundException
* @throws HttpMessageNotWritableException
* @throws IOException
*/
@AfterReturning(pointcut = "point()", returning = "data")
public void after(JoinPoint jp, Object data) throws Exception {
MethodInvocationProceedingJoinPoint joinPoint = (MethodInvocationProceedingJoinPoint) jp;
Class<?> clazz = joinPoint.getSignature().getDeclaringType();
if (AnnotationUtils.findAnnotation(clazz, FeignClient.class) == null) {
log.debug("未找到feign 客戶端");
return;
}
CustomSecurityContext securityContext = SecurityContextHystrixRequestVariable.getInstance().get();
ErrorResult errorResult = null;
if (securityContext != null && (errorResult = securityContext.getErrorResult()) != null) {
if (errorResult.getHttpStatus() != HttpStatus.OK.value()) {
Class<?> exceptionClass = Class.forName(errorResult.getException());
Constructor<?> constructor = exceptionClass.getConstructor(new Class[]{String.class, String.class});
throw (CustomException) constructor
.newInstance(new Object[]{errorResult.getMessage(), errorResult.getCode()});
}
}
SecurityContextHystrixRequestVariable.getInstance().remove();
}
開發者ID:zhaoqilong3031,項目名稱:spring-cloud-samples,代碼行數:27,代碼來源:DefaultFeignExceptionHandlerInterceptor.java
示例2: feignWebRegistrations
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Bean
public WebMvcRegistrations feignWebRegistrations() {
return new WebMvcRegistrationsAdapter() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new RequestMappingHandlerMapping() {
@Override
protected boolean isHandler(Class<?> beanType) {
return super.isHandler(beanType) && (AnnotationUtils.findAnnotation(beanType, FeignClient.class) == null);
}
};
}
};
}
示例3: isHandler
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Override
protected boolean isHandler(Class<?> beanType) {
//避免springmvc 把抽象出來的帶有RequestMapping注解的client接口掃描到controller注冊
if(BootCloudUtils.isNetflixFeignClientPresent() && AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class)){
if(log.isInfoEnabled()){
log.info("ignore FeignClient: {}", beanType);
}
return false;
}
return super.isHandler(beanType);
}
示例4: processAnnotationOnClass
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Override
protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
super.processAnnotationOnClass(data, clz);
if (clz.isAnnotationPresent(FeignClient.class)) {
EnhanceFeignClient classAnnotation = findMergedAnnotation(clz, EnhanceFeignClient.class);
Optional<String> basePathOpt = getFeignBasePath(clz, classAnnotation);
if(basePathOpt.isPresent()){
data.template().insert(0, basePathOpt.get());
}
}
}
示例5: getFeignBasePath
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@SuppressWarnings("deprecation")
private Optional<String> getFeignBasePath(Class<?> clz, EnhanceFeignClient classAnnotation){
if (classAnnotation == null){
return Optional.empty();
}
String pathValue = classAnnotation.basePath();
if(StringUtils.isBlank(pathValue)){
FeignClient feignClient = findMergedAnnotation(clz, FeignClient.class);
String serviceName = StringUtils.isNotBlank(feignClient.name())?feignClient.name():feignClient.serviceId();
serviceName = SpringUtils.resolvePlaceholders(applicationContext, serviceName);
//不填,默認查找對應的配置 -> jfish.cloud.feign.basePath.serviceName
pathValue = FEIGN_BASE_PATH_KEY + serviceName;
pathValue = this.relaxedPropertyResolver.getProperty(pathValue);
}else if(pathValue.startsWith(FEIGN_BASE_PATH_TAG)){
//:serviceName -> jfish.cloud.feign.basePath.serviceName
pathValue = FEIGN_BASE_PATH_KEY + pathValue.substring(1);
pathValue = this.relaxedPropertyResolver.getProperty(pathValue);
}else if(ExpressionFacotry.DOLOR.isExpresstion(pathValue)){
//${basePath}
pathValue = SpringUtils.resolvePlaceholders(applicationContext, pathValue);
}
if(StringUtils.isBlank(pathValue)){
return Optional.empty();
}
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
// data.template().insert(0, pathValue);
return Optional.ofNullable(pathValue);
}
示例6: apply
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Override
public JAnnotationUse apply(ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) {
JAnnotationUse feignClient = generatableType.annotate(FeignClient.class);
feignClient.param("url", controllerMetadata.getControllerUrl());
feignClient.param("name", getClientName(controllerMetadata));
return feignClient;
}
示例7: testAnnnotations
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Test
public void testAnnnotations() throws Exception {
Map<String, Object> beans = this.context
.getBeansWithAnnotation(FeignClient.class);
assertTrue("Wrong clients: " + beans,
beans.containsKey(TestClient.class.getName()));
}
示例8: FeignClientAnnotationRelationshipDetector
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
public FeignClientAnnotationRelationshipDetector() {
super(FeignClient.class);
}
示例9: extractFromAnnotation
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Override
protected Set<Relationship> extractFromAnnotation(FeignClient annotation) {
Dependency dependency = Dependency.on(Component.of(annotation.name(), ComponentType.HTTP_APPLICATION));
return dependency.asRelationshipSet();
}
示例10: isHandler
import org.springframework.cloud.netflix.feign.FeignClient; //導入依賴的package包/類
@Override
protected boolean isHandler(Class<?> beanType) {
return super.isHandler(beanType) && !AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class);
}