1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

sentinel add docs and bug fix for 1.x branch

This commit is contained in:
fangjian0423
2018-12-12 16:04:56 +08:00
parent d9abffd110
commit 8f1b45b2e6
3 changed files with 113 additions and 56 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.alibaba.sentinel.custom;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -156,26 +155,22 @@ public class SentinelAutoConfiguration {
}
@Bean("sentinel-json-converter")
public JsonConverter jsonConverter(
@Qualifier("sentinel-object-mapper") ObjectMapper objectMapper) {
return new JsonConverter(objectMapper);
public JsonConverter jsonConverter() {
return new JsonConverter(objectMapper());
}
@Bean("sentinel-object-mapper")
public ObjectMapper objectMapper() {
private ObjectMapper objectMapper() {
return new ObjectMapper();
}
@ConditionalOnClass(XmlMapper.class)
protected static class SentinelXmlConfiguration {
@Bean("sentinel-xml-converter")
public XmlConverter xmlConverter(
@Qualifier("sentinel-xml-mapper") XmlMapper xmlMapper) {
return new XmlConverter(xmlMapper);
public XmlConverter xmlConverter() {
return new XmlConverter(xmlMapper());
}
@Bean("sentinel-xml-mapper")
public XmlMapper xmlMapper() {
private XmlMapper xmlMapper() {
return new XmlMapper();
}
}

View File

@@ -89,13 +89,14 @@ public class SentinelFeign {
// check fallback and fallbackFactory properties
if (void.class != fallback) {
fallbackInstance = getFromContext(name, "fallback", fallback,
target);
target.type());
return new SentinelInvocationHandler(target, dispatch,
new FallbackFactory.Default(fallbackInstance));
}
if (void.class != fallbackFactory) {
fallbackFactoryInstance = (FallbackFactory) getFromContext(name,
"fallbackFactory", fallbackFactory, target);
"fallbackFactory", fallbackFactory,
FallbackFactory.class);
return new SentinelInvocationHandler(target, dispatch,
fallbackFactoryInstance);
}
@@ -103,7 +104,7 @@ public class SentinelFeign {
}
private Object getFromContext(String name, String type,
Class fallbackType, Target target) {
Class fallbackType, Class targetType) {
Object fallbackInstance = feignContext.getInstance(name,
fallbackType);
if (fallbackInstance == null) {
@@ -112,10 +113,10 @@ public class SentinelFeign {
type, fallbackType, name));
}
if (!target.type().isAssignableFrom(fallbackType)) {
if (!targetType.isAssignableFrom(fallbackType)) {
throw new IllegalStateException(String.format(
"Incompatible %s instance. Fallback/fallbackFactory of type %s is not assignable to %s for feign client %s",
type, fallbackType, target.type(), name));
type, fallbackType, targetType, name));
}
return fallbackInstance;
}