mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 20:35:29 +08:00
spring3
This commit is contained in:
@ -28,8 +28,8 @@
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
</dependency>
|
||||
<!-- redis方式限流 -->
|
||||
<dependency>
|
||||
@ -58,10 +58,10 @@
|
||||
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||
</dependency>
|
||||
<!--- sentinel流控链路不生效 -->
|
||||
<dependency>
|
||||
<!--<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-web-servlet</artifactId>
|
||||
</dependency>
|
||||
</dependency>-->
|
||||
|
||||
|
||||
<!--健康监控-->
|
||||
@ -73,7 +73,7 @@
|
||||
<!-- Swagger API文档 -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -13,7 +13,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
@ -50,8 +50,8 @@ public class JeecgGatewayApplication implements CommandLineRunner {
|
||||
* @param indexHtml
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RouterFunction<ServerResponse> indexRouter(@Value("classpath:/META-INF/resources/doc.html") final org.springframework.core.io.Resource indexHtml) {
|
||||
return route(GET("/"), request -> ok().contentType(MediaType.TEXT_HTML).syncBody(indexHtml));
|
||||
}
|
||||
// @Bean
|
||||
// public RouterFunction<ServerResponse> indexRouter(@Value("classpath:/META-INF/resources/doc.html") final org.springframework.core.io.Resource indexHtml) {
|
||||
// return route(GET("/"), request -> ok().contentType(MediaType.TEXT_HTML).syncBody(indexHtml));
|
||||
// }
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
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: zyf
|
||||
* @date: 20210715
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
||||
//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: zyf
|
||||
// * @date: 20210715
|
||||
// */
|
||||
//@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;
|
||||
// }
|
||||
//}
|
||||
@ -7,7 +7,7 @@ import org.jeecg.common.modules.redis.listener.JeecgRedisListener;
|
||||
import org.jeecg.loader.DynamicRouteLoader;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 路由刷新监听(实现方式:redis监听handler)
|
||||
|
||||
@ -1,160 +1,160 @@
|
||||
package org.jeecg.handler.swagger;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
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;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import springfox.documentation.swagger.web.SwaggerResource;
|
||||
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 聚合各个服务的swagger接口
|
||||
* @author zyf
|
||||
* @date: 2022/4/21 10:55
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Primary
|
||||
public class MySwaggerResourceProvider implements SwaggerResourcesProvider {
|
||||
/**
|
||||
* swagger2默认的url后缀
|
||||
*/
|
||||
private static final String SWAGGER2URL = "/v2/api-docs";
|
||||
|
||||
/**
|
||||
* 网关路由
|
||||
*/
|
||||
private final RouteLocator routeLocator;
|
||||
/**
|
||||
* Nacos名字服务
|
||||
*/
|
||||
private NamingService naming;
|
||||
|
||||
/**
|
||||
* nacos服务地址
|
||||
*/
|
||||
@Value("${spring.cloud.nacos.discovery.server-addr}")
|
||||
private String serverAddr;
|
||||
/**
|
||||
* nacos namespace
|
||||
*/
|
||||
@Value("${spring.cloud.nacos.discovery.namespace:#{null}}")
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
* nacos groupName
|
||||
*/
|
||||
@Value("${spring.cloud.nacos.config.group:DEFAULT_GROUP:#{null}}")
|
||||
private String group;
|
||||
|
||||
/**
|
||||
* nacos username
|
||||
*/
|
||||
@Value("${spring.cloud.nacos.discovery.username:#{null}}")
|
||||
private String username;
|
||||
/**
|
||||
* nacos password
|
||||
*/
|
||||
@Value("${spring.cloud.nacos.discovery.password:#{null}}")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Swagger中需要排除的服务
|
||||
*/
|
||||
private String[] excludeServiceIds=new String[]{"jeecg-cloud-monitor"};
|
||||
|
||||
|
||||
/**
|
||||
* 网关应用名称
|
||||
*/
|
||||
@Value("${spring.application.name}")
|
||||
private String self;
|
||||
|
||||
@Autowired
|
||||
public MySwaggerResourceProvider(RouteLocator routeLocator) {
|
||||
this.routeLocator = routeLocator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwaggerResource> get() {
|
||||
List<SwaggerResource> resources = new ArrayList<>();
|
||||
List<String> routeHosts = new ArrayList<>();
|
||||
// 获取所有可用的host:serviceId
|
||||
routeLocator.getRoutes().filter(route -> route.getUri().getHost() != null)
|
||||
.filter(route -> !self.equals(route.getUri().getHost()))
|
||||
.subscribe(route ->{
|
||||
//update-begin---author:zyf ---date:20220413 for:过滤掉无效路由,避免接口文档报错无法打开
|
||||
boolean hasRoute=checkRoute(route.getId());
|
||||
if(hasRoute){
|
||||
routeHosts.add(route.getUri().getHost());
|
||||
}
|
||||
//update-end---author:zyf ---date:20220413 for:过滤掉无效路由,避免接口文档报错无法打开
|
||||
});
|
||||
|
||||
// 记录已经添加过的server,存在同一个应用注册了多个服务在nacos上
|
||||
Set<String> dealed = new HashSet<>();
|
||||
routeHosts.forEach(instance -> {
|
||||
// 拼接url
|
||||
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");
|
||||
swaggerResource.setName(instance);
|
||||
//Swagger排除不展示的服务
|
||||
if(!ArrayUtil.contains(excludeServiceIds,instance)){
|
||||
resources.add(swaggerResource);
|
||||
}
|
||||
}
|
||||
});
|
||||
return resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测nacos中是否有健康实例
|
||||
* @param routeId
|
||||
* @return
|
||||
*/
|
||||
private Boolean checkRoute(String routeId) {
|
||||
Boolean hasRoute = false;
|
||||
try {
|
||||
//修复使用带命名空间启动网关swagger看不到接口文档的问题
|
||||
Properties properties=new Properties();
|
||||
properties.setProperty("serverAddr",serverAddr);
|
||||
if(namespace!=null && !"".equals(namespace)){
|
||||
log.info("nacos.discovery.namespace = {}", namespace);
|
||||
properties.setProperty("namespace",namespace);
|
||||
}
|
||||
if(username!=null && !"".equals(username)){
|
||||
properties.setProperty("username",username);
|
||||
}
|
||||
if(password!=null && !"".equals(password)){
|
||||
properties.setProperty("password",password);
|
||||
}
|
||||
//【issues/5115】因swagger文档导致gateway内存溢出
|
||||
if (this.naming == null) {
|
||||
this.naming = NamingFactory.createNamingService(properties);
|
||||
}
|
||||
log.info(" config.group : {}", group);
|
||||
List<Instance> list = this.naming.selectInstances(routeId, group , true);
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
hasRoute = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return hasRoute;
|
||||
}
|
||||
}
|
||||
//package org.jeecg.handler.swagger;
|
||||
//
|
||||
//import cn.hutool.core.util.ArrayUtil;
|
||||
//import cn.hutool.core.util.ObjectUtil;
|
||||
//import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
//import com.alibaba.nacos.api.naming.NamingService;
|
||||
//import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
//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;
|
||||
//import org.springframework.context.annotation.Primary;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import springfox.documentation.swagger.web.SwaggerResource;
|
||||
//import springfox.documentation.swagger.web.SwaggerResourcesProvider;
|
||||
//
|
||||
//import java.util.*;
|
||||
//
|
||||
///**
|
||||
// * 聚合各个服务的swagger接口
|
||||
// * @author zyf
|
||||
// * @date: 2022/4/21 10:55
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//@Primary
|
||||
//public class MySwaggerResourceProvider implements SwaggerResourcesProvider {
|
||||
// /**
|
||||
// * swagger2默认的url后缀
|
||||
// */
|
||||
// private static final String SWAGGER2URL = "/v2/api-docs";
|
||||
//
|
||||
// /**
|
||||
// * 网关路由
|
||||
// */
|
||||
// private final RouteLocator routeLocator;
|
||||
// /**
|
||||
// * Nacos名字服务
|
||||
// */
|
||||
// private NamingService naming;
|
||||
//
|
||||
// /**
|
||||
// * nacos服务地址
|
||||
// */
|
||||
// @Value("${spring.cloud.nacos.discovery.server-addr}")
|
||||
// private String serverAddr;
|
||||
// /**
|
||||
// * nacos namespace
|
||||
// */
|
||||
// @Value("${spring.cloud.nacos.discovery.namespace:#{null}}")
|
||||
// private String namespace;
|
||||
//
|
||||
// /**
|
||||
// * nacos groupName
|
||||
// */
|
||||
// @Value("${spring.cloud.nacos.config.group:DEFAULT_GROUP:#{null}}")
|
||||
// private String group;
|
||||
//
|
||||
// /**
|
||||
// * nacos username
|
||||
// */
|
||||
// @Value("${spring.cloud.nacos.discovery.username:#{null}}")
|
||||
// private String username;
|
||||
// /**
|
||||
// * nacos password
|
||||
// */
|
||||
// @Value("${spring.cloud.nacos.discovery.password:#{null}}")
|
||||
// private String password;
|
||||
//
|
||||
// /**
|
||||
// * Swagger中需要排除的服务
|
||||
// */
|
||||
// private String[] excludeServiceIds=new String[]{"jeecg-cloud-monitor"};
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 网关应用名称
|
||||
// */
|
||||
// @Value("${spring.application.name}")
|
||||
// private String self;
|
||||
//
|
||||
// @Autowired
|
||||
// public MySwaggerResourceProvider(RouteLocator routeLocator) {
|
||||
// this.routeLocator = routeLocator;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<SwaggerResource> get() {
|
||||
// List<SwaggerResource> resources = new ArrayList<>();
|
||||
// List<String> routeHosts = new ArrayList<>();
|
||||
// // 获取所有可用的host:serviceId
|
||||
// routeLocator.getRoutes().filter(route -> route.getUri().getHost() != null)
|
||||
// .filter(route -> !self.equals(route.getUri().getHost()))
|
||||
// .subscribe(route ->{
|
||||
// //update-begin---author:zyf ---date:20220413 for:过滤掉无效路由,避免接口文档报错无法打开
|
||||
// boolean hasRoute=checkRoute(route.getId());
|
||||
// if(hasRoute){
|
||||
// routeHosts.add(route.getUri().getHost());
|
||||
// }
|
||||
// //update-end---author:zyf ---date:20220413 for:过滤掉无效路由,避免接口文档报错无法打开
|
||||
// });
|
||||
//
|
||||
// // 记录已经添加过的server,存在同一个应用注册了多个服务在nacos上
|
||||
// Set<String> dealed = new HashSet<>();
|
||||
// routeHosts.forEach(instance -> {
|
||||
// // 拼接url
|
||||
// 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");
|
||||
// swaggerResource.setName(instance);
|
||||
// //Swagger排除不展示的服务
|
||||
// if(!ArrayUtil.contains(excludeServiceIds,instance)){
|
||||
// resources.add(swaggerResource);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// return resources;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 检测nacos中是否有健康实例
|
||||
// * @param routeId
|
||||
// * @return
|
||||
// */
|
||||
// private Boolean checkRoute(String routeId) {
|
||||
// Boolean hasRoute = false;
|
||||
// try {
|
||||
// //修复使用带命名空间启动网关swagger看不到接口文档的问题
|
||||
// Properties properties=new Properties();
|
||||
// properties.setProperty("serverAddr",serverAddr);
|
||||
// if(namespace!=null && !"".equals(namespace)){
|
||||
// log.info("nacos.discovery.namespace = {}", namespace);
|
||||
// properties.setProperty("namespace",namespace);
|
||||
// }
|
||||
// if(username!=null && !"".equals(username)){
|
||||
// properties.setProperty("username",username);
|
||||
// }
|
||||
// if(password!=null && !"".equals(password)){
|
||||
// properties.setProperty("password",password);
|
||||
// }
|
||||
// //【issues/5115】因swagger文档导致gateway内存溢出
|
||||
// if (this.naming == null) {
|
||||
// this.naming = NamingFactory.createNamingService(properties);
|
||||
// }
|
||||
// log.info(" config.group : {}", group);
|
||||
// List<Instance> list = this.naming.selectInstances(routeId, group , true);
|
||||
// if (ObjectUtil.isNotEmpty(list)) {
|
||||
// hasRoute = true;
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return hasRoute;
|
||||
// }
|
||||
//}
|
||||
@ -1,41 +1,41 @@
|
||||
package org.jeecg.handler.swagger;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.swagger.web.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* swagger聚合接口,三个接口都是 doc.html需要访问的接口
|
||||
* @author zyf
|
||||
* @date: 2022/4/21 10:55
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/swagger-resources")
|
||||
public class SwaggerResourceController {
|
||||
private MySwaggerResourceProvider swaggerResourceProvider;
|
||||
|
||||
@Autowired
|
||||
public SwaggerResourceController(MySwaggerResourceProvider swaggerResourceProvider) {
|
||||
this.swaggerResourceProvider = swaggerResourceProvider;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configuration/security")
|
||||
public ResponseEntity<SecurityConfiguration> securityConfiguration() {
|
||||
return new ResponseEntity<>(SecurityConfigurationBuilder.builder().build(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/configuration/ui")
|
||||
public ResponseEntity<UiConfiguration> uiConfiguration() {
|
||||
return new ResponseEntity<>(UiConfigurationBuilder.builder().build(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping
|
||||
public ResponseEntity<List<SwaggerResource>> swaggerResources() {
|
||||
return new ResponseEntity<>(swaggerResourceProvider.get(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
//package org.jeecg.handler.swagger;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//import springfox.documentation.swagger.web.*;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * swagger聚合接口,三个接口都是 doc.html需要访问的接口
|
||||
// * @author zyf
|
||||
// * @date: 2022/4/21 10:55
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/swagger-resources")
|
||||
//public class SwaggerResourceController {
|
||||
// private MySwaggerResourceProvider swaggerResourceProvider;
|
||||
//
|
||||
// @Autowired
|
||||
// public SwaggerResourceController(MySwaggerResourceProvider swaggerResourceProvider) {
|
||||
// this.swaggerResourceProvider = swaggerResourceProvider;
|
||||
// }
|
||||
//
|
||||
// @RequestMapping(value = "/configuration/security")
|
||||
// public ResponseEntity<SecurityConfiguration> securityConfiguration() {
|
||||
// return new ResponseEntity<>(SecurityConfigurationBuilder.builder().build(), HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// @RequestMapping(value = "/configuration/ui")
|
||||
// public ResponseEntity<UiConfiguration> uiConfiguration() {
|
||||
// return new ResponseEntity<>(UiConfigurationBuilder.builder().build(), HttpStatus.OK);
|
||||
// }
|
||||
//
|
||||
// @RequestMapping
|
||||
// public ResponseEntity<List<SwaggerResource>> swaggerResources() {
|
||||
// return new ResponseEntity<>(swaggerResourceProvider.get(), HttpStatus.OK);
|
||||
// }
|
||||
//}
|
||||
@ -9,10 +9,7 @@ import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.base.BaseMap;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
@ -32,6 +29,8 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.net.URI;
|
||||
@ -109,7 +108,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
* @return
|
||||
*/
|
||||
private void loadRoutesByNacos() {
|
||||
List<RouteDefinition> routes = Lists.newArrayList();
|
||||
List<RouteDefinition> routes = Collections.emptyList();
|
||||
configService = createConfigService();
|
||||
if (configService == null) {
|
||||
log.warn("initConfigService fail");
|
||||
@ -118,7 +117,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
log.info("jeecg.route.config.data-id = {}", gatewayRoutersConfig.getDataId());
|
||||
log.info("nacos.config.group = {}", gatewayRoutersConfig.getRouteGroup());
|
||||
String configInfo = configService.getConfig(gatewayRoutersConfig.getDataId(), gatewayRoutersConfig.getRouteGroup(), DEFAULT_TIMEOUT);
|
||||
if (StringUtils.isNotBlank(configInfo)) {
|
||||
if (StringUtils.hasText(configInfo)) {
|
||||
log.info("获取网关当前配置:\r\n{}", configInfo);
|
||||
routes = JSON.parseArray(configInfo, RouteDefinition.class);
|
||||
}else{
|
||||
@ -143,7 +142,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
* @return
|
||||
*/
|
||||
private void loadRoutesByRedis(BaseMap baseMap) {
|
||||
List<MyRouteDefinition> routes = Lists.newArrayList();
|
||||
List<MyRouteDefinition> routes = Collections.emptyList();
|
||||
configService = createConfigService();
|
||||
if (configService == null) {
|
||||
log.warn("initConfigService fail");
|
||||
@ -170,9 +169,9 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
dynamicRouteService.add(definition);
|
||||
}
|
||||
}
|
||||
if(ObjectUtils.isNotEmpty(baseMap)){
|
||||
if(!ObjectUtils.isEmpty(baseMap)){
|
||||
String delRouterId = baseMap.get("delRouterId");
|
||||
if (ObjectUtils.isNotEmpty(delRouterId)) {
|
||||
if (!ObjectUtils.isEmpty(delRouterId)) {
|
||||
dynamicRouteService.delete(delRouterId);
|
||||
}
|
||||
}
|
||||
@ -360,13 +359,13 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("serverAddr", gatewayRoutersConfig.getServerAddr());
|
||||
if(StringUtils.isNotBlank(gatewayRoutersConfig.getNamespace())){
|
||||
if(StringUtils.hasText(gatewayRoutersConfig.getNamespace())){
|
||||
properties.setProperty("namespace", gatewayRoutersConfig.getNamespace());
|
||||
}
|
||||
if(StringUtils.isNotBlank( gatewayRoutersConfig.getUsername())){
|
||||
if(StringUtils.hasText( gatewayRoutersConfig.getUsername())){
|
||||
properties.setProperty("username", gatewayRoutersConfig.getUsername());
|
||||
}
|
||||
if(StringUtils.isNotBlank(gatewayRoutersConfig.getPassword())){
|
||||
if(StringUtils.hasText(gatewayRoutersConfig.getPassword())){
|
||||
properties.setProperty("password", gatewayRoutersConfig.getPassword());
|
||||
}
|
||||
return configService = NacosFactory.createConfigService(properties);
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
server:
|
||||
port: 9999
|
||||
|
||||
knife4j:
|
||||
gateway:
|
||||
enabled: true
|
||||
discover:
|
||||
excluded-services: ${spring.application.name}
|
||||
enabled: true
|
||||
strategy: discover
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: jeecg-gateway
|
||||
@ -8,21 +16,19 @@ spring:
|
||||
allow-circular-references: true
|
||||
config:
|
||||
import:
|
||||
- optional:nacos:${spring.application.name}-@profile.name@.yaml
|
||||
- optional:nacos:jeecg-gateway-dev.yaml
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: @config.server-addr@
|
||||
group: @config.group@
|
||||
namespace: @config.namespace@
|
||||
username: @config.username@
|
||||
password: @config.password@
|
||||
server-addr: localhost:8848
|
||||
namespace: public
|
||||
# username: @config.username@
|
||||
# password: @config.password@
|
||||
discovery:
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
group: @config.group@
|
||||
namespace: @config.namespace@
|
||||
username: @config.username@
|
||||
password: @config.password@
|
||||
namespace: public
|
||||
# username: @config.username@
|
||||
# password: @config.password@
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
@ -50,7 +56,7 @@ spring:
|
||||
flow: # 指定数据源名称
|
||||
# 指定nacos数据源
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
# 指定配置文件
|
||||
dataId: ${spring.application.name}-flow-rules
|
||||
# 指定分组
|
||||
@ -62,7 +68,7 @@ spring:
|
||||
#降级规则
|
||||
degrade:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-degrade-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: degrade
|
||||
@ -70,7 +76,7 @@ spring:
|
||||
#系统规则
|
||||
system:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-system-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: system
|
||||
@ -78,7 +84,7 @@ spring:
|
||||
#授权规则
|
||||
authority:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-authority-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: authority
|
||||
@ -86,7 +92,7 @@ spring:
|
||||
#热点参数
|
||||
param-flow:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-param-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: param-flow
|
||||
@ -94,7 +100,7 @@ spring:
|
||||
#网关流控规则
|
||||
gw-flow:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-flow-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: gw-flow
|
||||
@ -102,7 +108,7 @@ spring:
|
||||
#API流控规则
|
||||
gw-api-group:
|
||||
nacos:
|
||||
server-addr: @config.server-addr@
|
||||
server-addr: ${spring.cloud.nacos.config.server-addr}
|
||||
dataId: ${spring.application.name}-api-rules
|
||||
groupId: SENTINEL_GROUP
|
||||
rule-type: gw-api-group
|
||||
|
||||
@ -30,11 +30,12 @@ spring:
|
||||
username: root
|
||||
password: root
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
redis:
|
||||
database: 0
|
||||
host: jeecg-boot-redis
|
||||
password:
|
||||
port: 6379
|
||||
data:
|
||||
redis:
|
||||
database: 0
|
||||
host: jeecg-boot-redis
|
||||
password:
|
||||
port: 6379
|
||||
rabbitmq:
|
||||
host: jeecg-boot-rabbitmq
|
||||
username: guest
|
||||
|
||||
@ -6,8 +6,9 @@ jeecg:
|
||||
group: DEFAULT_GROUP
|
||||
data-id: jeecg-gateway-router
|
||||
spring:
|
||||
redis:
|
||||
database: 0
|
||||
host: jeecg-boot-redis
|
||||
port: 6379
|
||||
password:
|
||||
data:
|
||||
redis:
|
||||
database: 0
|
||||
host: jeecg-boot-redis
|
||||
port: 6379
|
||||
password:
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jeecg;
|
||||
|
||||
import com.xkcoding.justauth.autoconfigure.JustAuthAutoConfiguration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.base.BaseMap;
|
||||
import org.jeecg.common.constant.GlobalConstants;
|
||||
@ -7,6 +8,7 @@ import org.jeecg.common.util.oConvertUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
@ -29,6 +31,7 @@ import java.net.UnknownHostException;
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients(basePackages = {"org.jeecg"})
|
||||
@EnableScheduling
|
||||
@ImportAutoConfiguration(JustAuthAutoConfiguration.class) // spring boot 3.x justauth 兼容性处理
|
||||
public class JeecgSystemCloudApplication extends SpringBootServletInitializer implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
|
||||
@ -19,13 +19,19 @@
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<version>3.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-properties-migrator</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--安全模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -2,8 +2,9 @@ package org.jeecg.monitor.config;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.AdminServerProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
|
||||
|
||||
@ -11,7 +12,7 @@ import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
|
||||
* @author scott
|
||||
*/
|
||||
@Configuration
|
||||
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
|
||||
public class SecuritySecureConfig {
|
||||
|
||||
private final String adminContextPath;
|
||||
|
||||
@ -20,32 +21,40 @@ public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
|
||||
// 登录成功处理类
|
||||
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
successHandler.setTargetUrlParameter("redirectTo");
|
||||
successHandler.setDefaultTargetUrl(adminContextPath + "/");
|
||||
|
||||
http.authorizeRequests()
|
||||
//静态文件允许访问
|
||||
.antMatchers(adminContextPath + "/assets/**").permitAll()
|
||||
//登录页面允许访问
|
||||
.antMatchers(adminContextPath + "/login", "/css/**", "/js/**", "/image/*").permitAll()
|
||||
//其他所有请求需要登录
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
//登录页面配置,用于替换security默认页面
|
||||
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
|
||||
//登出页面配置,用于替换security默认页面
|
||||
.logout().logoutUrl(adminContextPath + "/logout").and()
|
||||
.httpBasic().and()
|
||||
.csrf()
|
||||
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
|
||||
.ignoringAntMatchers(
|
||||
"/instances",
|
||||
"/actuator/**"
|
||||
);
|
||||
http.authorizeRequests(authorize -> {
|
||||
try {
|
||||
authorize
|
||||
|
||||
//静态文件允许访问
|
||||
.requestMatchers(adminContextPath + "/assets/**").permitAll()
|
||||
//登录页面允许访问
|
||||
.requestMatchers(adminContextPath + "/login", "/css/**", "/js/**", "/image/*").permitAll()
|
||||
//其他所有请求需要登录
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
//登录页面配置,用于替换security默认页面
|
||||
.formLogin(formLogin -> formLogin.loginPage(adminContextPath + "/login").successHandler(successHandler))
|
||||
//登出页面配置,用于替换security默认页面
|
||||
.logout(logout -> logout.logoutUrl(adminContextPath + "/logout"))
|
||||
.httpBasic(Customizer.withDefaults())
|
||||
.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
|
||||
.ignoringRequestMatchers(
|
||||
"/instances",
|
||||
"/actuator/**")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return http.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3,15 +3,20 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>jeecg-visual</artifactId>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<version>3.6.1</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.10</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>jeecg-cloud-sentinel</artifactId>
|
||||
<name>jeecg-cloud-sentinel</name>
|
||||
<description>sentinel启动模块</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.cloud</groupId>
|
||||
<artifactId>sentinel-dashboard</artifactId>
|
||||
|
||||
@ -12,7 +12,7 @@ spring:
|
||||
mvc:
|
||||
#Spring Boot 2.6+\u540E\u6620\u5C04\u5339\u914D\u7684\u9ED8\u8BA4\u7B56\u7565\u5DF2\u4ECEAntPathMatcher\u66F4\u6539\u4E3APathPatternParser,\u9700\u8981\u624B\u52A8\u6307\u5B9A\u4E3Aant-path-matcher
|
||||
pathmatch:
|
||||
matching-strategy: ant-path-matcher
|
||||
matching-strategy: ant_path_matcher
|
||||
#auth settings
|
||||
auth:
|
||||
filter:
|
||||
@ -29,7 +29,7 @@ logging:
|
||||
name: ${user.home}/logs/csp/sentinel-dashboard.log
|
||||
nacos:
|
||||
server:
|
||||
ip: @config.server-addr@
|
||||
ip: localhost:8848
|
||||
sentinel:
|
||||
dashboard:
|
||||
version: 1.8.2
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package org.jeecg.modules.test.feign.controller;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
@ -8,8 +10,6 @@ import org.jeecg.modules.test.feign.client.JeecgTestClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* 微服务单元测试
|
||||
@ -19,7 +19,7 @@ import io.swagger.annotations.ApiOperation;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/sys/test")
|
||||
@Api(tags = "【微服务】单元测试")
|
||||
@Tag(name = "【微服务】单元测试")
|
||||
public class JeecgTestFeignController {
|
||||
|
||||
@Autowired
|
||||
@ -32,7 +32,7 @@ public class JeecgTestFeignController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getMessage")
|
||||
@ApiOperation(value = "测试feign调用demo服务1", notes = "测试feign @SentinelResource熔断写法 | 测试熔断关闭jeecg-demo服务")
|
||||
@Operation(summary = "测试feign @SentinelResource熔断写法 | 测试熔断关闭jeecg-demo服务")
|
||||
@SentinelResource(value = "test_more_getMessage", fallback = "getDefaultUser")
|
||||
public Result<String> getMessage(@RequestParam(value = "name", required = false) String name) {
|
||||
log.info("---------Feign fallbackFactory优先级高于@SentinelResource-----------------");
|
||||
@ -47,7 +47,7 @@ public class JeecgTestFeignController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getMessage2")
|
||||
@ApiOperation(value = "测试feign调用demo服务2", notes = "测试feign fallbackFactory熔断写法 | 测试熔断关闭jeecg-demo服务")
|
||||
@Operation(summary = "测试feign fallbackFactory熔断写法 | 测试熔断关闭jeecg-demo服务")
|
||||
public Result<String> getMessage2(@RequestParam(value = "name", required = false) String name) {
|
||||
log.info("---------测试 Feign fallbackFactory-----------------");
|
||||
String resultMsg = jeecgTestClient.getMessage(" I am jeecg-system 服务节点,呼叫 jeecg-demo!");
|
||||
@ -56,7 +56,7 @@ public class JeecgTestFeignController {
|
||||
|
||||
|
||||
@GetMapping("/fallback")
|
||||
@ApiOperation(value = "测试熔断", notes = "测试熔断")
|
||||
@Operation(summary = "测试熔断")
|
||||
@SentinelResource(value = "test_more_fallback", fallback = "getDefaultUser")
|
||||
public Result<Object> test(@RequestParam(value = "name", required = false) String name) {
|
||||
if (StringUtils.isEmpty(name)) {
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package org.jeecg.modules.test.rabbitmq.controller;
|
||||
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
@ -13,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
|
||||
/**
|
||||
@ -24,7 +24,7 @@ import io.swagger.annotations.ApiOperation;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/test")
|
||||
@Api(tags = "【微服务】MQ单元测试")
|
||||
@Tag(name = "【微服务】MQ单元测试")
|
||||
public class JeecgMqTestController {
|
||||
|
||||
@Autowired
|
||||
@ -39,7 +39,7 @@ public class JeecgMqTestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/rabbitmq")
|
||||
@ApiOperation(value = "测试rabbitmq", notes = "测试rabbitmq")
|
||||
@Operation(summary = "测试rabbitmq")
|
||||
public Result<?> rabbitMqClientTest(HttpServletRequest req) {
|
||||
//rabbitmq消息队列测试
|
||||
BaseMap map = new BaseMap();
|
||||
@ -50,7 +50,7 @@ public class JeecgMqTestController {
|
||||
}
|
||||
|
||||
@GetMapping(value = "/rabbitmq2")
|
||||
@ApiOperation(value = "rabbitmq消息总线测试", notes = "rabbitmq消息总线测试")
|
||||
@Operation(summary = "rabbitmq消息总线测试")
|
||||
public Result<?> rabbitmq2(HttpServletRequest req) {
|
||||
|
||||
//rabbitmq消息总线测试
|
||||
|
||||
@ -13,7 +13,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
server:
|
||||
port: 5002
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
password:
|
||||
ssl:
|
||||
enabled: false
|
||||
application:
|
||||
name: seata-account
|
||||
main:
|
||||
@ -18,8 +27,13 @@ spring:
|
||||
password: root
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
schema: classpath:sql/schema-account.sql
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
import-check:
|
||||
enabled: false
|
||||
seata:
|
||||
enable-auto-data-source-proxy: false
|
||||
enable-auto-data-source-proxy: true
|
||||
service:
|
||||
grouplist:
|
||||
default: 127.0.0.1:8091
|
||||
|
||||
@ -6,9 +6,9 @@ package org.jeecg.modules.test.seata.order.controller;
|
||||
* @date: 2022/01/24
|
||||
* @version: V1.0
|
||||
*/
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.jeecg.modules.test.seata.order.dto.PlaceOrderRequest;
|
||||
import org.jeecg.modules.test.seata.order.service.SeataOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test/seata/order")
|
||||
@Api(tags = "seata测试")
|
||||
@Tag(name = "seata测试")
|
||||
public class SeataOrderController {
|
||||
|
||||
@Autowired
|
||||
@ -30,7 +30,7 @@ public class SeataOrderController {
|
||||
* 自由下单
|
||||
*/
|
||||
@PostMapping("/placeOrder")
|
||||
@ApiOperation(value = "自由下单", notes = "自由下单")
|
||||
@Operation(summary = "自由下单")
|
||||
public String placeOrder(@Validated @RequestBody PlaceOrderRequest request) {
|
||||
orderService.placeOrder(request);
|
||||
return "下单成功";
|
||||
@ -40,7 +40,7 @@ public class SeataOrderController {
|
||||
* 测试商品库存不足-异常回滚
|
||||
*/
|
||||
@PostMapping("/test1")
|
||||
@ApiOperation(value = "测试商品库存不足", notes = "测试商品库存不足")
|
||||
@Operation(summary = "测试商品库存不足")
|
||||
public String test1() {
|
||||
//商品单价10元,库存20个,用户余额50元,模拟一次性购买22个。 期望异常回滚
|
||||
orderService.placeOrder(new PlaceOrderRequest(1L, 1L, 22));
|
||||
@ -51,7 +51,7 @@ public class SeataOrderController {
|
||||
* 测试用户账户余额不足-异常回滚
|
||||
*/
|
||||
@PostMapping("/test2")
|
||||
@ApiOperation(value = "测试用户账户余额不足", notes = "测试用户账户余额不足")
|
||||
@Operation(summary = "测试用户账户余额不足")
|
||||
public String test2() {
|
||||
//商品单价10元,库存20个,用户余额50元,模拟一次性购买6个。 期望异常回滚
|
||||
orderService.placeOrder(new PlaceOrderRequest(1L, 1L, 6));
|
||||
|
||||
@ -4,7 +4,7 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
/**
|
||||
* @Description: 订单请求对象
|
||||
* @author: zyf
|
||||
|
||||
@ -16,7 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,12 +1,21 @@
|
||||
server:
|
||||
port: 5001
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
password:
|
||||
ssl:
|
||||
enabled: false
|
||||
application:
|
||||
name: seata-order
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
autoconfigure:
|
||||
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
|
||||
exclude: com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure
|
||||
datasource:
|
||||
dynamic:
|
||||
primary: order
|
||||
@ -19,6 +28,11 @@ spring:
|
||||
username: root
|
||||
password: root
|
||||
schema: classpath:sql/schema-order.sql
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
import-check:
|
||||
enabled: false
|
||||
seata:
|
||||
enable-auto-data-source-proxy: false
|
||||
service:
|
||||
|
||||
@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ public class SeataProductController {
|
||||
private SeataProductService seataProductService;
|
||||
|
||||
@PostMapping("/reduceStock")
|
||||
public BigDecimal reduceStock(Long productId, Integer count) {
|
||||
public BigDecimal reduceStock(Long productId, Integer count, HttpServletRequest request) {
|
||||
return seataProductService.reduceStock(productId, count);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,15 @@
|
||||
server:
|
||||
port: 5003
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
password:
|
||||
ssl:
|
||||
enabled: false
|
||||
application:
|
||||
name: seata-product
|
||||
main:
|
||||
@ -18,6 +27,11 @@ spring:
|
||||
username: root
|
||||
password: root
|
||||
schema: classpath:sql/schema-product.sql
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
import-check:
|
||||
enabled: false
|
||||
seata:
|
||||
enable-auto-data-source-proxy: false
|
||||
service:
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package org.jeecg.modules.test.sharding.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
@ -10,8 +12,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@ -21,7 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "分库分表测试")
|
||||
@Tag(name = "分库分表测试")
|
||||
@RestController
|
||||
@RequestMapping("/sharding")
|
||||
public class JeecgShardingDemoController extends JeecgController<ShardingSysLog, IShardingSysLogService> {
|
||||
@ -33,7 +33,7 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/test1")
|
||||
@ApiOperation(value = "单库分表插入", notes = "单库分表")
|
||||
@Operation(summary = "单库分表")
|
||||
public Result<?> add() {
|
||||
log.info("---------------------------------单库分表插入--------------------------------");
|
||||
int size = 10;
|
||||
@ -52,7 +52,7 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/list1")
|
||||
@ApiOperation(value = "单库分表查询", notes = "单库分表")
|
||||
@Operation(summary = "单库分表")
|
||||
public Result<?> list() {
|
||||
return Result.OK(shardingSysLogService.list());
|
||||
}
|
||||
@ -62,7 +62,7 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/test2")
|
||||
@ApiOperation(value = "分库分表插入", notes = "分库分表")
|
||||
@Operation(summary = "分库分表")
|
||||
public Result<?> test2() {
|
||||
int start=20;
|
||||
int size=30;
|
||||
@ -81,7 +81,7 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/list2")
|
||||
@ApiOperation(value = "分库分表查询", notes = "分库分表")
|
||||
@Operation(summary = "分库分表")
|
||||
public Result<?> list2() {
|
||||
return Result.OK(shardingSysLogService.list());
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.3</version>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
<!-- mysql -->
|
||||
<dependency>
|
||||
|
||||
@ -13,9 +13,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@ -14,8 +14,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@ -12,8 +12,8 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -14,8 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
||||
@ -22,8 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@ -23,8 +23,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@ -16,8 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -2,13 +2,13 @@ package com.xxl.job.admin.controller.interceptor;
|
||||
|
||||
import com.xxl.job.admin.core.util.FtlUtil;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -17,7 +17,7 @@ import java.util.HashMap;
|
||||
* @author xuxueli 2015-12-12 18:09:04
|
||||
*/
|
||||
@Component
|
||||
public class CookieInterceptor extends HandlerInterceptorAdapter {
|
||||
public class CookieInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
@ -36,8 +36,7 @@ public class CookieInterceptor extends HandlerInterceptorAdapter {
|
||||
if (modelAndView != null) {
|
||||
modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName()));
|
||||
}
|
||||
|
||||
super.postHandle(request, response, handler, modelAndView);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,13 +4,12 @@ import com.xxl.job.admin.controller.annotation.PermissionLimit;
|
||||
import com.xxl.job.admin.core.model.XxlJobUser;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.admin.service.LoginService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
/**
|
||||
* 权限拦截
|
||||
@ -18,7 +17,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
* @author xuxueli 2015-12-12 18:09:04
|
||||
*/
|
||||
@Component
|
||||
public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
||||
public class PermissionInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
@ -27,7 +26,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
return super.preHandle(request, response, handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if need login
|
||||
@ -53,7 +52,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
||||
request.setAttribute(LoginService.LOGIN_IDENTITY_KEY, loginUser);
|
||||
}
|
||||
|
||||
return super.preHandle(request, response, handler);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
/**
|
||||
* web mvc config
|
||||
|
||||
@ -11,8 +11,8 @@ import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
|
||||
@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package com.xxl.job.admin.core.util;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Cookie.Util
|
||||
|
||||
@ -9,9 +9,9 @@ import com.xxl.job.core.biz.model.ReturnT;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
|
||||
@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -17,7 +17,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
Reference in New Issue
Block a user