mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fixes #227
This commit is contained in:
parent
3f1194a87a
commit
608337c93d
@ -28,6 +28,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
|||||||
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.type.StandardMethodMetadata;
|
import org.springframework.core.type.StandardMethodMetadata;
|
||||||
|
import org.springframework.core.type.classreading.MethodMetadataReadingVisitor;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@ -49,9 +50,16 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
||||||
Class<?> beanType, String beanName) {
|
Class<?> beanType, String beanName) {
|
||||||
if (checkSentinelProtect(beanDefinition, beanType)) {
|
if (checkSentinelProtect(beanDefinition, beanType)) {
|
||||||
SentinelRestTemplate sentinelRestTemplate = ((StandardMethodMetadata) beanDefinition
|
SentinelRestTemplate sentinelRestTemplate;
|
||||||
.getSource()).getIntrospectedMethod()
|
if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
|
||||||
.getAnnotation(SentinelRestTemplate.class);
|
sentinelRestTemplate = ((StandardMethodMetadata) beanDefinition
|
||||||
|
.getSource()).getIntrospectedMethod()
|
||||||
|
.getAnnotation(SentinelRestTemplate.class);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sentinelRestTemplate = beanDefinition.getResolvedFactoryMethod()
|
||||||
|
.getAnnotation(SentinelRestTemplate.class);
|
||||||
|
}
|
||||||
cache.put(beanName, sentinelRestTemplate);
|
cache.put(beanName, sentinelRestTemplate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,11 +67,22 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
||||||
Class<?> beanType) {
|
Class<?> beanType) {
|
||||||
return beanType == RestTemplate.class
|
return beanType == RestTemplate.class
|
||||||
&& beanDefinition.getSource() instanceof StandardMethodMetadata
|
&& (checkStandardMethodMetadata(beanDefinition)
|
||||||
|
|| checkMethodMetadataReadingVisitor(beanDefinition));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkStandardMethodMetadata(RootBeanDefinition beanDefinition) {
|
||||||
|
return beanDefinition.getSource() instanceof StandardMethodMetadata
|
||||||
&& ((StandardMethodMetadata) beanDefinition.getSource())
|
&& ((StandardMethodMetadata) beanDefinition.getSource())
|
||||||
.isAnnotated(SentinelRestTemplate.class.getName());
|
.isAnnotated(SentinelRestTemplate.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkMethodMetadataReadingVisitor(RootBeanDefinition beanDefinition) {
|
||||||
|
return beanDefinition.getSource() instanceof MethodMetadataReadingVisitor
|
||||||
|
&& ((MethodMetadataReadingVisitor) beanDefinition.getSource())
|
||||||
|
.isAnnotated(SentinelRestTemplate.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||||
throws BeansException {
|
throws BeansException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user