mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 20:35:29 +08:00
JeecgBoot 3.3.0 版本发布,基于代码生成器的企业级低代码平台
This commit is contained in:
@ -10,6 +10,6 @@ WORKDIR /jeecg-cloud-gateway
|
||||
|
||||
EXPOSE 9999
|
||||
|
||||
ADD ./target/jeecg-cloud-gateway-3.2.0.jar ./
|
||||
ADD ./target/jeecg-cloud-gateway-3.3.0.jar ./
|
||||
|
||||
CMD sleep 50;java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-gateway-3.2.0.jar
|
||||
CMD sleep 50;java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-gateway-3.3.0.jar
|
||||
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>jeecg-cloud-module</artifactId>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jeecg-cloud-gateway</artifactId>
|
||||
|
||||
@ -1,15 +1,24 @@
|
||||
package org.jeecg;
|
||||
|
||||
import org.jeecg.loader.DynamicRouteLoader;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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 static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
|
||||
|
||||
/**
|
||||
* @author jeecg
|
||||
*/
|
||||
@ -17,7 +26,6 @@ import javax.annotation.Resource;
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class JeecgGatewayApplication implements CommandLineRunner {
|
||||
|
||||
@Resource
|
||||
private DynamicRouteLoader dynamicRouteLoader;
|
||||
|
||||
@ -35,4 +43,15 @@ public class JeecgGatewayApplication implements CommandLineRunner {
|
||||
public void run(String... strings) {
|
||||
dynamicRouteLoader.refresh(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口地址(通过9999端口直接访问)
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author scott
|
||||
* @date 2020/05/26
|
||||
* 路由配置信息
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
public class GatewayRoutersConfig {
|
||||
/**
|
||||
* 路由配置方式:database,yml,nacos
|
||||
*/
|
||||
public String dataType;
|
||||
public String serverAddr;
|
||||
public String namespace;
|
||||
public String dataId;
|
||||
public String routeGroup;
|
||||
public String username;
|
||||
public String password;
|
||||
|
||||
@Value("${spring.cloud.nacos.discovery.server-addr}")
|
||||
public void setServerAddr(String serverAddr) {
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.nacos.discovery.namespace}")
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
@Value("${jeecg.route.config.data-id:#{null}}")
|
||||
public void setRouteDataId(String dataId) {
|
||||
this.dataId = dataId + ".json";
|
||||
}
|
||||
|
||||
@Value("${jeecg.route.config.group:DEFAULT_GROUP:#{null}}")
|
||||
public void setRouteGroup(String routeGroup) {
|
||||
this.routeGroup = routeGroup;
|
||||
}
|
||||
|
||||
@Value("${jeecg.route.config.data-type:#{null}}")
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.nacos.config.username}")
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.nacos.config.password}")
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public String getServerAddr() {
|
||||
return serverAddr;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public String getRouteGroup() {
|
||||
return routeGroup;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
package org.jeecg.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
|
||||
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
||||
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
|
||||
|
||||
/**
|
||||
* @author scott
|
||||
* @date 2020/05/26
|
||||
* 路由配置信息
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
public class GatewayRoutersConfiguration {
|
||||
|
||||
public static final long DEFAULT_TIMEOUT = 30000;
|
||||
public static String SERVER_ADDR;
|
||||
public static String NAMESPACE;
|
||||
public static String DATA_ID;
|
||||
public static String ROUTE_GROUP;
|
||||
public static String USERNAME;
|
||||
public static String PASSWORD;
|
||||
|
||||
@Value("${spring.cloud.nacos.discovery.server-addr}")
|
||||
public void setServerAddr(String serverAddr) {
|
||||
SERVER_ADDR = serverAddr;
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.nacos.discovery.namespace}")
|
||||
public void setNamespace(String namespace) {
|
||||
NAMESPACE = namespace;
|
||||
}
|
||||
|
||||
@Value("${jeecg.route.config.data-id:#{null}}")
|
||||
public void setRouteDataId(String dataId) {
|
||||
DATA_ID = dataId + ".json";
|
||||
}
|
||||
|
||||
@Value("${jeecg.route.config.group:DEFAULT_GROUP:#{null}}")
|
||||
public void setRouteGroup(String routeGroup) {
|
||||
ROUTE_GROUP = routeGroup;
|
||||
}
|
||||
|
||||
|
||||
@Value("${spring.cloud.nacos.config.username}")
|
||||
public void setUsername(String username) {
|
||||
USERNAME = username;
|
||||
}
|
||||
|
||||
@Value("${spring.cloud.nacos.config.password}")
|
||||
public void setPassword(String password) {
|
||||
PASSWORD = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 接口地址(通过9999端口直接访问)
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,12 +16,12 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.base.BaseMap;
|
||||
import org.jeecg.common.constant.CacheConstant;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.config.GatewayRoutersConfiguration;
|
||||
import org.jeecg.config.GatewayRoutersConfig;
|
||||
import org.jeecg.config.RouterDataType;
|
||||
import org.jeecg.loader.repository.DynamicRouteService;
|
||||
import org.jeecg.loader.repository.MyInMemoryRouteDefinitionRepository;
|
||||
import org.jeecg.loader.vo.MyRouteDefinition;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
|
||||
import org.springframework.cloud.gateway.filter.FilterDefinition;
|
||||
@ -33,7 +33,6 @@ import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
@ -50,22 +49,20 @@ import java.util.concurrent.Executor;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@DependsOn({"gatewayRoutersConfiguration"})
|
||||
@RefreshScope
|
||||
@DependsOn({"gatewayRoutersConfig"})
|
||||
public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
|
||||
|
||||
public static final long DEFAULT_TIMEOUT = 30000;
|
||||
@Autowired
|
||||
private GatewayRoutersConfig gatewayRoutersConfig;
|
||||
private MyInMemoryRouteDefinitionRepository repository;
|
||||
private ApplicationEventPublisher publisher;
|
||||
private DynamicRouteService dynamicRouteService;
|
||||
private ConfigService configService;
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 路由配置方式:database(数据库),yml(配置文件),nacos
|
||||
*/
|
||||
@Value("${jeecg.route.config.data-type:database}")
|
||||
public String dataType;
|
||||
|
||||
/**
|
||||
* 需要拼接key的路由条件
|
||||
*/
|
||||
@ -85,12 +82,12 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
|
||||
|
||||
public void init(BaseMap baseMap) {
|
||||
log.info("初始化路由,dataType:"+ dataType);
|
||||
if (RouterDataType.nacos.toString().endsWith(dataType)) {
|
||||
log.info("初始化路由模式,dataType:"+ gatewayRoutersConfig.getDataType());
|
||||
if (RouterDataType.nacos.toString().endsWith(gatewayRoutersConfig.getDataType())) {
|
||||
loadRoutesByNacos();
|
||||
}
|
||||
//从数据库加载路由
|
||||
if (RouterDataType.database.toString().endsWith(dataType)) {
|
||||
if (RouterDataType.database.toString().endsWith(gatewayRoutersConfig.getDataType())) {
|
||||
loadRoutesByRedis(baseMap);
|
||||
}
|
||||
}
|
||||
@ -100,7 +97,8 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
* @return
|
||||
*/
|
||||
public Mono<Void> refresh(BaseMap baseMap) {
|
||||
if (!RouterDataType.yml.toString().endsWith(dataType)) {
|
||||
log.info("初始化路由模式,dataType:"+ gatewayRoutersConfig.getDataType());
|
||||
if (!RouterDataType.yml.toString().endsWith(gatewayRoutersConfig.getDataType())) {
|
||||
this.init(baseMap);
|
||||
}
|
||||
return Mono.empty();
|
||||
@ -119,7 +117,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
log.warn("initConfigService fail");
|
||||
}
|
||||
try {
|
||||
String configInfo = configService.getConfig(GatewayRoutersConfiguration.DATA_ID, GatewayRoutersConfiguration.ROUTE_GROUP, GatewayRoutersConfiguration.DEFAULT_TIMEOUT);
|
||||
String configInfo = configService.getConfig(gatewayRoutersConfig.getDataId(), gatewayRoutersConfig.getRouteGroup(), DEFAULT_TIMEOUT);
|
||||
if (StringUtils.isNotBlank(configInfo)) {
|
||||
log.info("获取网关当前配置:\r\n{}", configInfo);
|
||||
routes = JSON.parseArray(configInfo, RouteDefinition.class);
|
||||
@ -133,7 +131,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
dynamicRouteService.add(definition);
|
||||
}
|
||||
this.publisher.publishEvent(new RefreshRoutesEvent(this));
|
||||
dynamicRouteByNacosListener(GatewayRoutersConfiguration.DATA_ID, GatewayRoutersConfiguration.ROUTE_GROUP);
|
||||
dynamicRouteByNacosListener(gatewayRoutersConfig.getDataId(), gatewayRoutersConfig.getRouteGroup());
|
||||
}
|
||||
|
||||
|
||||
@ -340,10 +338,10 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
||||
private ConfigService createConfigService() {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("serverAddr", GatewayRoutersConfiguration.SERVER_ADDR);
|
||||
properties.setProperty("namespace", GatewayRoutersConfiguration.NAMESPACE);
|
||||
properties.setProperty("username",GatewayRoutersConfiguration.USERNAME);
|
||||
properties.setProperty("password",GatewayRoutersConfiguration.PASSWORD);
|
||||
properties.setProperty("serverAddr", gatewayRoutersConfig.getServerAddr());
|
||||
properties.setProperty("namespace", gatewayRoutersConfig.getNamespace());
|
||||
properties.setProperty("username", gatewayRoutersConfig.getUsername());
|
||||
properties.setProperty("password", gatewayRoutersConfig.getPassword());
|
||||
return configService = NacosFactory.createConfigService(properties);
|
||||
} catch (Exception e) {
|
||||
log.error("创建ConfigService异常", e);
|
||||
|
||||
Reference in New Issue
Block a user