mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
✨ Introducing new features. #2324 up spring cloud 2020.0.1
This commit is contained in:
1 parent
3af30a0e9e
commit
fe191320e3
4 files changed
+22
-71
No files matched your search
@@ -4,9 +4,9 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>pigx-cloud-dependencies-parent</artifactId>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<version>Hoxton.SR9</version>
|
||||
<groupId>group.springframework</groupId>
|
||||
<artifactId>spring-cloud-dependencies-parent</artifactId>
|
||||
<version>2020.0.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<properties>
|
||||
<pigx.version>4.0.0-SNAPSHOT</pigx.version>
|
||||
<mybatis-plus.version>3.4.1</mybatis-plus.version>
|
||||
<mybatis-plus.version>3.4.2</mybatis-plus.version>
|
||||
<dynamic-ds.version>3.2.0</dynamic-ds.version>
|
||||
<druid.version>1.2.4</druid.version>
|
||||
<mysql.connector.version>8.0.22</mysql.connector.version>
|
||||
@@ -32,7 +32,7 @@
|
||||
<aliyun.version>3.0.52.ALL</aliyun.version>
|
||||
<javaformat.plugin.version>0.0.23</javaformat.plugin.version>
|
||||
<docker.plugin.version>0.33.0</docker.plugin.version>
|
||||
<cloud.plugin.version>1.1.1</cloud.plugin.version>
|
||||
<cloud.plugin.version>1.0.0</cloud.plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -216,40 +216,6 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--避免和parent bom坐标不一致 -->
|
||||
<plugin>
|
||||
<groupId>com.pig4cloud.plugin</groupId>
|
||||
<artifactId>spring-cloud-maven-plugin</artifactId>
|
||||
<version>${cloud.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>info</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- nothing to do, but we need this to run docker:build form project root -->
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>${docker.plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--代码格式插件,默认使用spring 规则-->
|
||||
<plugin>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
<version>${javaformat.plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>aliyun-plugin</id>
|
||||
|
||||
+2
-2
@@ -36,8 +36,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
@EnableCaching
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
@AutoConfigureBefore(name = {"org.redisson.spring.starter.RedissonAutoConfiguration"
|
||||
, "org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration"})
|
||||
@AutoConfigureBefore(name = { "org.redisson.spring.starter.RedissonAutoConfiguration",
|
||||
"org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration" })
|
||||
public class RedisTemplateConfig {
|
||||
|
||||
@Bean
|
||||
|
||||
+12
-27
@@ -1,5 +1,9 @@
|
||||
package com.pig4cloud.pigx.common.sentinel.feign;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.sentinel.feign.SentinelContractHolder;
|
||||
import feign.Contract;
|
||||
import feign.Feign;
|
||||
@@ -7,17 +11,13 @@ import feign.InvocationHandlerFactory;
|
||||
import feign.Target;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.cloud.openfeign.FeignContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 重写 {@link com.alibaba.cloud.sentinel.feign.SentinelFeign} 支持自动降级注入
|
||||
*
|
||||
@@ -58,17 +58,14 @@ public final class PigxSentinelFeign {
|
||||
super.invocationHandlerFactory(new InvocationHandlerFactory() {
|
||||
@Override
|
||||
public InvocationHandler create(Target target, Map<Method, MethodHandler> dispatch) {
|
||||
// using reflect get fallback and fallbackFactory properties from
|
||||
// FeignClientFactoryBean because FeignClientFactoryBean is a package
|
||||
// level class, we can not use it in our package
|
||||
Object feignClientFactoryBean = PigxSentinelFeign.Builder.this.applicationContext
|
||||
.getBean("&" + target.type().getName());
|
||||
// 查找 FeignClient 上的 降级策略
|
||||
FeignClient feignClient = AnnotationUtils.findAnnotation(target.type(), FeignClient.class);
|
||||
Class fallback = feignClient.fallback();
|
||||
Class fallbackFactory = feignClient.fallbackFactory();
|
||||
|
||||
Class fallback = (Class) getFieldValue(feignClientFactoryBean, "fallback");
|
||||
Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, "fallbackFactory");
|
||||
String beanName = (String) getFieldValue(feignClientFactoryBean, "contextId");
|
||||
String beanName = feignClient.contextId();
|
||||
if (!StringUtils.hasText(beanName)) {
|
||||
beanName = (String) getFieldValue(feignClientFactoryBean, "name");
|
||||
beanName = feignClient.name();
|
||||
}
|
||||
|
||||
Object fallbackInstance;
|
||||
@@ -107,18 +104,6 @@ public final class PigxSentinelFeign {
|
||||
return super.build();
|
||||
}
|
||||
|
||||
private Object getFieldValue(Object instance, String fieldName) {
|
||||
Field field = ReflectionUtils.findField(instance.getClass(), fieldName);
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
return field.get(instance);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.4.1</spring-boot.version>
|
||||
<spring-cloud.version>2020.0.0</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2.2.3.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring-cloud.version>2020.0.1</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2.2.5.RELEASE</spring-cloud-alibaba.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
@@ -44,7 +44,7 @@
|
||||
<git.commit.version>2.2.5</git.commit.version>
|
||||
<spring-boot-admin.version>2.3.1</spring-boot-admin.version>
|
||||
<hutool.version>5.5.7</hutool.version>
|
||||
<captcha.version>1.2.5</captcha.version>
|
||||
<captcha.version>1.2.7</captcha.version>
|
||||
<swagger.fox.version>3.0.0</swagger.fox.version>
|
||||
<knife4j.version>3.0.2</knife4j.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
|
||||
Reference in new issue
Block a user