From cf63212f94f78a282aba969ee69be8025d128501 Mon Sep 17 00:00:00 2001 From: zlt Date: Tue, 24 Mar 2020 11:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=AC=E5=85=B1starter?= =?UTF-8?q?=E7=9A=84bean=E5=8A=A0=E8=BD=BD=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=BE=9D=E8=B5=96=E7=9A=84=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E5=9B=A0=E5=8C=85=E8=B7=AF=E5=BE=84=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E8=80=8C=E5=AF=BC=E8=87=B4=E5=8A=A0=E8=BD=BD=E4=B8=8D=E4=BA=86?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/annotation/EnableSearchClient.java | 5 ++- .../SearchServiceFallbackFactory.java | 2 - .../common/config/TokenStoreConfig.java | 38 ------------------- .../oauth2/common/store/AuthDbTokenStore.java | 3 +- .../common/store/AuthJwtTokenStore.java | 2 + .../common/store/AuthRedisTokenStore.java | 2 + .../oauth2/common/store/ResJwtTokenStore.java | 2 + .../main/resources/META-INF/spring.factories | 6 ++- .../fallback/UserServiceFallbackFactory.java | 2 - .../main/resources/META-INF/spring.factories | 5 ++- .../common/redis/RedisAutoConfigure.java | 13 ------- .../redis/lock/RedisDistributedLock.java | 1 - .../main/resources/META-INF/spring.factories | 4 +- .../swagger2/Swagger2Configuration.java | 2 - .../main/resources/application-dev.properties | 2 +- 15 files changed, 24 insertions(+), 65 deletions(-) delete mode 100644 zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/TokenStoreConfig.java diff --git a/zlt-business/search-center/search-client/src/main/java/com/central/search/annotation/EnableSearchClient.java b/zlt-business/search-center/search-client/src/main/java/com/central/search/annotation/EnableSearchClient.java index 5ff59b7f..9d86183e 100644 --- a/zlt-business/search-center/search-client/src/main/java/com/central/search/annotation/EnableSearchClient.java +++ b/zlt-business/search-center/search-client/src/main/java/com/central/search/annotation/EnableSearchClient.java @@ -1,5 +1,6 @@ package com.central.search.annotation; +import com.central.search.client.feign.fallback.SearchServiceFallbackFactory; import com.central.search.client.service.impl.QueryServiceImpl; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Import; @@ -16,8 +17,8 @@ import java.lang.annotation.Target; */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@EnableFeignClients -@Import(QueryServiceImpl.class) +@EnableFeignClients(basePackages = "com.central") +@Import({SearchServiceFallbackFactory.class, QueryServiceImpl.class}) public @interface EnableSearchClient { } diff --git a/zlt-business/search-center/search-client/src/main/java/com/central/search/client/feign/fallback/SearchServiceFallbackFactory.java b/zlt-business/search-center/search-client/src/main/java/com/central/search/client/feign/fallback/SearchServiceFallbackFactory.java index 131310ca..7623ef26 100644 --- a/zlt-business/search-center/search-client/src/main/java/com/central/search/client/feign/fallback/SearchServiceFallbackFactory.java +++ b/zlt-business/search-center/search-client/src/main/java/com/central/search/client/feign/fallback/SearchServiceFallbackFactory.java @@ -5,7 +5,6 @@ import com.central.common.model.PageResult; import com.central.search.client.feign.SearchService; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; /** * searchService降级工场 @@ -13,7 +12,6 @@ import org.springframework.stereotype.Component; * @author zlt */ @Slf4j -@Component public class SearchServiceFallbackFactory implements FallbackFactory { @Override public SearchService create(Throwable throwable) { diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/TokenStoreConfig.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/TokenStoreConfig.java deleted file mode 100644 index 29fdc618..00000000 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/config/TokenStoreConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.central.oauth2.common.config; - -import com.central.oauth2.common.store.*; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * token存储配置 - * - * @author zlt - */ -@Configuration -public class TokenStoreConfig { - @Configuration - @ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "db") - @Import(AuthDbTokenStore.class) - public class JdbcTokenConfig { - } - - @Configuration - @ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "redis", matchIfMissing = true) - @Import(AuthRedisTokenStore.class) - public class RedisTokenConfig { - } - - @Configuration - @ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "authJwt") - @Import(AuthJwtTokenStore.class) - public class AuthJwtTokenConfig { - } - - @Configuration - @ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "resJwt") - @Import(ResJwtTokenStore.class) - public class ResJwtTokenConfig { - } -} diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java index 5b4727ae..d084e549 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthDbTokenStore.java @@ -1,6 +1,7 @@ package com.central.oauth2.common.store; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; @@ -13,8 +14,8 @@ import javax.sql.DataSource; * @author zlt * @date 2018/7/24 16:23 */ +@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "db") public class AuthDbTokenStore { - @Autowired private DataSource dataSource; diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java index 0892a3da..9b99fb79 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java @@ -2,6 +2,7 @@ package com.central.oauth2.common.store; import com.central.common.model.SysUser; import com.central.oauth2.common.converter.CustomUserAuthenticationConverter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.bootstrap.encrypt.KeyProperties; import org.springframework.context.annotation.Bean; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; @@ -23,6 +24,7 @@ import java.util.Map; * @author zlt * @date 2018/7/24 16:21 */ +@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "authJwt") public class AuthJwtTokenStore { @Bean("keyProp") diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java index ada4c027..a8651589 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthRedisTokenStore.java @@ -2,6 +2,7 @@ package com.central.oauth2.common.store; import com.central.oauth2.common.properties.SecurityProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.security.oauth2.provider.token.TokenStore; @@ -13,6 +14,7 @@ import org.springframework.security.oauth2.provider.token.TokenStore; * @author zlt * @date 2018/7/25 9:36 */ +@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "redis", matchIfMissing = true) public class AuthRedisTokenStore { @Autowired private RedisConnectionFactory connectionFactory; diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java index 39efc124..606fbb68 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/ResJwtTokenStore.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import com.central.common.constant.SecurityConstants; import com.central.oauth2.common.converter.CustomUserAuthenticationConverter; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; import org.springframework.context.annotation.Bean; import org.springframework.core.io.ClassPathResource; @@ -30,6 +31,7 @@ import java.util.stream.Collectors; * @author zlt * @date 2018/8/20 9:25 */ +@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "resJwt") public class ResJwtTokenStore { @Autowired private ResourceServerProperties resource; diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/resources/META-INF/spring.factories index 479efca8..f45f3e08 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,2 +1,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.central.oauth2.common.config.SecurityPropertiesConfig \ No newline at end of file +com.central.oauth2.common.config.SecurityPropertiesConfig,\ +com.central.oauth2.common.store.AuthDbTokenStore,\ +com.central.oauth2.common.store.AuthRedisTokenStore,\ +com.central.oauth2.common.store.AuthJwtTokenStore,\ +com.central.oauth2.common.store.ResJwtTokenStore \ No newline at end of file diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java index aea588d9..cde1ff9a 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/feign/fallback/UserServiceFallbackFactory.java @@ -5,7 +5,6 @@ import com.central.common.model.LoginAppUser; import com.central.common.model.SysUser; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; /** * userService降级工场 @@ -14,7 +13,6 @@ import org.springframework.stereotype.Component; * @date 2019/1/18 */ @Slf4j -@Component public class UserServiceFallbackFactory implements FallbackFactory { @Override public UserService create(Throwable throwable) { diff --git a/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring.factories index 7c72414b..247a1118 100644 --- a/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring.factories +++ b/zlt-commons/zlt-common-core/src/main/resources/META-INF/spring.factories @@ -1,2 +1,5 @@ org.springframework.context.ApplicationContextInitializer=\ -com.central.common.config.BannerInitializer \ No newline at end of file +com.central.common.config.BannerInitializer + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.central.common.feign.fallback.UserServiceFallbackFactory \ No newline at end of file diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java index e4e9e6cb..3bc5e5b8 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java @@ -5,7 +5,6 @@ import com.central.common.redis.template.RedisRepository; import com.central.common.redis.util.RedisObjectSerializer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -53,18 +52,6 @@ public class RedisAutoConfigure { return redisTemplate; } - /** - * Redis repository redis repository. - * - * @param redisTemplate the redis template - * @return the redis repository - */ - @Bean - @ConditionalOnMissingBean - public RedisRepository redisRepository(RedisTemplate redisTemplate) { - return new RedisRepository(redisTemplate); - } - @Bean(name = "cacheManager") @Primary public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java index d4c29c3b..a4abd189 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedisDistributedLock.java @@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit; * @date 2018/5/29 14:16 */ @Slf4j -@Component public class RedisDistributedLock extends AbstractDistributedLock { @Autowired private RedisTemplate redisTemplate; diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-redis-spring-boot-starter/src/main/resources/META-INF/spring.factories index dca6421a..924601e9 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,2 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.central.common.redis.RedisAutoConfigure +com.central.common.redis.RedisAutoConfigure,\ +com.central.common.redis.lock.RedisDistributedLock,\ +com.central.common.redis.template.RedisRepository \ No newline at end of file diff --git a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/Swagger2Configuration.java b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/Swagger2Configuration.java index 7c0fc0ef..2903d4c4 100644 --- a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/Swagger2Configuration.java +++ b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/Swagger2Configuration.java @@ -1,7 +1,6 @@ package com.central.common.swagger2; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration; @@ -10,7 +9,6 @@ import springfox.documentation.swagger2.configuration.Swagger2DocumentationConfi * @author zlt * @date 2018/11/18 9:20 */ -@Configuration @ConditionalOnProperty(name = "zlt.swagger.enabled", matchIfMissing = true) @Import({ Swagger2DocumentationConfiguration.class diff --git a/zlt-config/src/main/resources/application-dev.properties b/zlt-config/src/main/resources/application-dev.properties index a8605465..93b4bf7d 100644 --- a/zlt-config/src/main/resources/application-dev.properties +++ b/zlt-config/src/main/resources/application-dev.properties @@ -11,7 +11,7 @@ spring.redis.timeout=5000 ##### elasticsearch配置 zlt.elasticsearch.cluster-name=my-es -zlt.elasticsearch.cluster-nodes=192.168.28.130 +zlt.elasticsearch.cluster-nodes=106.12.138.245 ##### sentinel配置 zlt.sentinel.dashboard=192.168.28.130:6999