mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 20:35:29 +08:00
JeecgBoot 2.4.6版本发布
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package org.jeecg.filter;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Configuration
|
||||
public class SentinelFilterContextConfig {
|
||||
@Bean
|
||||
public FilterRegistrationBean sentinelFilterRegistration() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
registration.setFilter(new CommonFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
// 入口资源关闭聚合
|
||||
registration.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
|
||||
registration.setName("sentinelFilter");
|
||||
registration.setOrder(1);
|
||||
return registration;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jeecg.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
@ -13,6 +14,7 @@ import java.util.*;
|
||||
* 聚合各个服务的swagger接口
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MySwaggerResourceProvider implements SwaggerResourcesProvider {
|
||||
/**
|
||||
* swagger2默认的url后缀
|
||||
@ -51,6 +53,7 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider {
|
||||
String url = "/" + instance.toLowerCase() + SWAGGER2URL;
|
||||
if (!dealed.contains(url)) {
|
||||
dealed.add(url);
|
||||
log.info(" Gateway add SwaggerResource: {}",url);
|
||||
SwaggerResource swaggerResource = new SwaggerResource();
|
||||
swaggerResource.setUrl(url);
|
||||
swaggerResource.setSwaggerVersion("2.0");
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
package org.jeecg.handler;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
|
||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 自定义限流返回信息
|
||||
* @author Administrator
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SentinelBlockRequestHandler implements BlockRequestHandler {
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@PostConstruct
|
||||
public void doInit() {
|
||||
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, inetUtils.findFirstNonLoopbackAddress().getHostAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable ex) {
|
||||
String resultString = "{\"code\":403,\"message\":\"服务开启限流保护,请稍后再试!\"}";
|
||||
return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS).contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(resultString));
|
||||
}
|
||||
|
||||
}
|
||||
@ -4,6 +4,13 @@ spring:
|
||||
application:
|
||||
name: jeecg-gateway
|
||||
cloud:
|
||||
#Sentinel配置
|
||||
sentinel:
|
||||
web-context-unify: false
|
||||
transport:
|
||||
dashboard: localhost:8087
|
||||
# 懒加载Sentinel Dashboard菜单
|
||||
eager: false
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
|
||||
Reference in New Issue
Block a user