微服务模式部署下,nacos的账户密码如果不使用默认提供的nacos/nacos,会导致gateway读取路由信息失败 #2375

pull/2398/head
zhangdaiscott 2021-03-28 19:45:50 +08:00
parent cbd8890cb3
commit a674340c5e
2 changed files with 20 additions and 2 deletions

View File

@ -37,6 +37,10 @@ public class GatewayRoutersConfiguration {
public static String ROUTE_GROUP;
public static String USERNAME;
public static String PASSWORD;
/**
* yml,nacos,database
*/
@ -63,8 +67,15 @@ public class GatewayRoutersConfiguration {
}
@Value("${jeecg.route.config.data-type}")
public void setDataType(String dataType) {
DATA_TYPE = dataType;
public void setDataType(String dataType) { DATA_TYPE = dataType; }
@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;
}
@ -79,6 +90,11 @@ public class GatewayRoutersConfiguration {
}
/**
* 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));

View File

@ -299,6 +299,8 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
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);
return configService = NacosFactory.createConfigService(properties);
} catch (Exception e) {
log.error("创建ConfigService异常", e);