Merge pull request #152 from fangjian0423/master

fix bugs about sentinel starter
pull/164/head
xiaojing 6 years ago committed by GitHub
commit f76eafd38b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save