✨ Introducing new features. close #I4ZJ0S sentinel 适配 spring cloud alibaba 2021.0.1.0
This commit is contained in:
1 parent
c825dc181e
commit
b9f57016c8
3 files changed
+1
-62
No files matched your search
-3
@@ -21,7 +21,6 @@ import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
|
|||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
||||||
import com.pig4cloud.pigx.common.sentinel.feign.PigxSentinelFeign;
|
import com.pig4cloud.pigx.common.sentinel.feign.PigxSentinelFeign;
|
||||||
import com.pig4cloud.pigx.common.sentinel.feign.PigxSentinelFilterConfiguration;
|
|
||||||
import com.pig4cloud.pigx.common.sentinel.handle.PigxUrlBlockHandler;
|
import com.pig4cloud.pigx.common.sentinel.handle.PigxUrlBlockHandler;
|
||||||
import com.pig4cloud.pigx.common.sentinel.parser.PigxHeaderRequestOriginParser;
|
import com.pig4cloud.pigx.common.sentinel.parser.PigxHeaderRequestOriginParser;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
@@ -30,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +38,6 @@ import org.springframework.context.annotation.Scope;
|
|||||||
* sentinel 配置
|
* sentinel 配置
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(PigxSentinelFilterConfiguration.class)
|
|
||||||
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
|
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
|
||||||
public class SentinelAutoConfiguration {
|
public class SentinelAutoConfiguration {
|
||||||
|
|
||||||
|
|||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
package com.pig4cloud.pigx.common.sentinel.feign;
|
|
||||||
|
|
||||||
import com.alibaba.cloud.sentinel.SentinelProperties;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lengleng
|
|
||||||
* @date 2021/12/4
|
|
||||||
*
|
|
||||||
* 避免 spring cloud 2021 不兼容 的问题
|
|
||||||
*/
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
|
||||||
public class PigxSentinelFilterConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SentinelWebInterceptor sentinelWebInterceptor(SentinelWebMvcConfig sentinelWebMvcConfig) {
|
|
||||||
return new SentinelWebInterceptor(sentinelWebMvcConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SentinelWebMvcConfig sentinelWebMvcConfig(SentinelProperties properties,
|
|
||||||
Optional<UrlCleaner> urlCleanerOptional, Optional<BlockExceptionHandler> blockExceptionHandlerOptional,
|
|
||||||
Optional<RequestOriginParser> requestOriginParserOptional) {
|
|
||||||
SentinelWebMvcConfig sentinelWebMvcConfig = new SentinelWebMvcConfig();
|
|
||||||
sentinelWebMvcConfig.setHttpMethodSpecify(properties.getHttpMethodSpecify());
|
|
||||||
sentinelWebMvcConfig.setWebContextUnify(properties.getWebContextUnify());
|
|
||||||
|
|
||||||
if (blockExceptionHandlerOptional.isPresent()) {
|
|
||||||
blockExceptionHandlerOptional.ifPresent(sentinelWebMvcConfig::setBlockExceptionHandler);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (StringUtils.hasText(properties.getBlockPage())) {
|
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(
|
|
||||||
((request, response, e) -> response.sendRedirect(properties.getBlockPage())));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(new DefaultBlockExceptionHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
urlCleanerOptional.ifPresent(sentinelWebMvcConfig::setUrlCleaner);
|
|
||||||
requestOriginParserOptional.ifPresent(sentinelWebMvcConfig::setOriginParser);
|
|
||||||
return sentinelWebMvcConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ server:
|
|||||||
db:
|
db:
|
||||||
num: 1
|
num: 1
|
||||||
user: ${MYSQL_USER:root}
|
user: ${MYSQL_USER:root}
|
||||||
password: ${MYSQL_PWD:123456}
|
password: ${MYSQL_PWD:root}
|
||||||
url:
|
url:
|
||||||
0: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_config}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
0: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_config}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user