NutzCN Logo
问答 nutzboot-starter-nacos-config无法自动加载application.properties
发布于 1751天前 作者 baocj 8767 次浏览 复制 上一个帖子 下一个帖子
标签:

求助,用最新的2.3.9-SNAPSHOT nutzboot-demo-simple-jetty-nacos-config-client版本来测试(已经改过pom配置),无法自动加载application.properties,导致nacos配置取不到,以下为现象及配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>nutzboot-demo-simple</artifactId>
        <groupId>org.nutz</groupId>
        <version>2.3.9-SNAPSHOT</version>
    </parent>
    <artifactId>nutzboot-demo-simple-jetty-nacos-config-client</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-nutz-mvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nutz</groupId>
            <artifactId>nutzboot-starter-nacos-config</artifactId>
        </dependency>
        <dependency>
        	<groupId>org.slf4j</groupId>
        	<artifactId>slf4j-log4j12</artifactId>
        </dependency>
    </dependencies>
</project>
nacos.config.server-addr=192.168.71:8848
nacos.config.data_id=wk-nb-service-cms
nacos.config.group=DEFAULT_GROUP
nacos.config.data_type=properties

/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/bin/java "-javaagent:/Users/baocj/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.6494.35/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=54483:/Users/baocj/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.6494.35/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/lib/tools.jar:/Users/baocj/IdeaProjects/nutzboot/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-jetty-nacos-config-client/target/classes:/Users/baocj/IdeaProjects/nutzboot/nutzboot-starter/nutzboot-starter-nutz-mvc/target/classes:/Users/baocj/IdeaProjects/nutzboot/nutzboot-starter/nutzboot-starter-jetty/target/classes:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-servlets/9.4.27.v20200227/jetty-servlets-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-continuation/9.4.27.v20200227/jetty-continuation-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-http/9.4.27.v20200227/jetty-http-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-util/9.4.27.v20200227/jetty-util-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-io/9.4.27.v20200227/jetty-io-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-webapp/9.4.27.v20200227/jetty-webapp-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-xml/9.4.27.v20200227/jetty-xml-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-servlet/9.4.27.v20200227/jetty-servlet-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-security/9.4.27.v20200227/jetty-security-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-server/9.4.27.v20200227/jetty-server-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.4.27.v20200227/websocket-server-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.4.27.v20200227/websocket-common-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.4.27.v20200227/websocket-api-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.4.27.v20200227/websocket-client-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-client/9.4.27.v20200227/jetty-client-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.4.27.v20200227/websocket-servlet-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/javax-websocket-server-impl/9.4.27.v20200227/javax-websocket-server-impl-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-annotations/9.4.27.v20200227/jetty-annotations-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/jetty-plus/9.4.27.v20200227/jetty-plus-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/org/ow2/asm/asm-commons/6.1.1/asm-commons-6.1.1.jar:/Users/baocj/.m2/repository/org/ow2/asm/asm-tree/6.1.1/asm-tree-6.1.1.jar:/Users/baocj/.m2/repository/org/ow2/asm/asm-analysis/6.1.1/asm-analysis-6.1.1.jar:/Users/baocj/.m2/repository/org/eclipse/jetty/websocket/javax-websocket-client-impl/9.4.27.v20200227/javax-websocket-client-impl-9.4.27.v20200227.jar:/Users/baocj/.m2/repository/javax/websocket/javax.websocket-client-api/1.0/javax.websocket-client-api-1.0.jar:/Users/baocj/.m2/repository/javax/websocket/javax.websocket-api/1.0/javax.websocket-api-1.0.jar:/Users/baocj/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/Users/baocj/.m2/repository/org/nutz/nutz-plugins-websocket/1.r.68-SNAPSHOT/nutz-plugins-websocket-1.r.68-20200306.120058-52.jar:/Users/baocj/IdeaProjects/nutzboot/nutzboot-starter/nutzboot-servlet3/target/classes:/Users/baocj/.m2/repository/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.jar:/Users/baocj/.m2/repository/org/ow2/asm/asm/6.1.1/asm-6.1.1.jar:/Users/baocj/IdeaProjects/nutzboot/nutzboot-starter/nutzboot-starter-nacos-config/target/classes:/Users/baocj/.m2/repository/com/alibaba/nacos/nacos-client/1.1.4/nacos-client-1.1.4.jar:/Users/baocj/.m2/repository/com/alibaba/nacos/nacos-common/1.1.4/nacos-common-1.1.4.jar:/Users/baocj/.m2/repository/commons-io/commons-io/2.2/commons-io-2.2.jar:/Users/baocj/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar:/Users/baocj/.m2/repository/com/alibaba/nacos/nacos-api/1.1.4/nacos-api-1.1.4.jar:/Users/baocj/.m2/repository/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.jar:/Users/baocj/.m2/repository/com/google/guava/guava/22.0/guava-22.0.jar:/Users/baocj/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/Users/baocj/.m2/repository/com/google/errorprone/error_prone_annotations/2.0.18/error_prone_annotations-2.0.18.jar:/Users/baocj/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar:/Users/baocj/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar:/Users/baocj/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar:/Users/baocj/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.10/jackson-core-2.9.10.jar:/Users/baocj/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.10/jackson-databind-2.9.10.jar:/Users/baocj/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.10/jackson-annotations-2.9.10.jar:/Users/baocj/.m2/repository/io/prometheus/simpleclient/0.5.0/simpleclient-0.5.0.jar:/Users/baocj/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar:/Users/baocj/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/baocj/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar:/Users/baocj/IdeaProjects/nutzboot/nutzboot-core/target/classes:/Users/baocj/.m2/repository/org/nutz/nutz/1.r.68-SNAPSHOT/nutz-1.r.68-20200224.073715-91.jar:/Users/baocj/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar io.nutz.demo.simple.MainLauncher
[INFO ] 11:30:10.898 org.nutz.boot.banner.SimpleBannerPrinter.printBanner(SimpleBannerPrinter.java:34) - 
 _   _ ______                                      ___   
| \ | || ___ \  ______ ______ ______ ______ ______| \ \  
|  \| || |_/ / |______|______|______|______|______| |\ \ 
| . ` || ___ \  ______ ______ ______ ______ ______| | > >
| |\  || |_/ / |______|______|______|______|______| |/ / 
\_| \_/\____/                                     |_/_/  
  
:: Nutz Boot ::   (2.3.8.v20191031)

[DEBUG] 11:30:10.911 org.nutz.boot.NbApp.prepareConfigureLoader(NbApp.java:359) - using org.nutz.boot.starter.nacos.NacosConfigureLoader as ConfigureLoader
[WARN ] 11:30:10.939 com.alibaba.nacos.client.utils.LogUtils.<clinit>(LogUtils.java:53) - Load Log4j Configuration of Nacos fail, message: org/apache/logging/log4j/LogManager
[INFO ] 11:30:10.972 com.alibaba.nacos.client.utils.ParamUtil.<clinit>(ParamUtil.java:57) - [settings] [req-serv] nacos-server port:8848
[INFO ] 11:30:10.973 com.alibaba.nacos.client.utils.ParamUtil.<clinit>(ParamUtil.java:68) - [settings] [http-client] connect timeout:1000
[INFO ] 11:30:10.977 com.alibaba.nacos.client.utils.ParamUtil.<clinit>(ParamUtil.java:80) - NACOS_CLIENT_VERSION: unknown
[INFO ] 11:30:10.978 com.alibaba.nacos.client.utils.ParamUtil.<clinit>(ParamUtil.java:87) - PER_TASK_CONFIG_SIZE: 3000.0
[INFO ] 11:30:11.044 com.alibaba.nacos.client.identify.CredentialWatcher.loadCredential(CredentialWatcher.java:150) - null No credential found
[INFO ] 11:30:11.066 com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor.<clinit>(LocalConfigInfoProcessor.java:195) - LOCAL_SNAPSHOT_PATH:/Users/baocj/nacos/config
[INFO ] 11:30:11.253 com.alibaba.nacos.client.config.impl.Limiter.<clinit>(Limiter.java:53) - limitTime:5.0
[ERROR] 11:30:11.334 com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:94) - [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
[ERROR] 11:30:11.508 com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:94) - [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
[ERROR] 11:30:11.705 com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:94) - [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
[ERROR] 11:30:11.906 com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:94) - [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
[ERROR] 11:30:11.907 com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:239) - [fixed-127.0.0.1_8848] [sub-server] get server config exception, dataId=nutzboot, group=DEFAULT_GROUP, tenant=
java.net.ConnectException: [NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached
	at com.alibaba.nacos.client.config.http.ServerHttpAgent.httpGet(ServerHttpAgent.java:107)
	at com.alibaba.nacos.client.config.http.MetricsHttpAgent.httpGet(MetricsHttpAgent.java:48)
	at com.alibaba.nacos.client.config.impl.ClientWorker.getServerConfig(ClientWorker.java:234)
	at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:173)
	at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:122)
	at org.nutz.boot.starter.nacos.NacosConfigureLoader.init(NacosConfigureLoader.java:132)
	at org.nutz.boot.NbApp.prepareConfigureLoader(NbApp.java:370)
	at org.nutz.boot.NbApp.prepare(NbApp.java:268)
	at org.nutz.boot.NbApp.execute(NbApp.java:201)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at io.nutz.demo.simple.MainLauncher.main(MainLauncher.java:30)
[WARN ] 11:30:11.913 com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:185) - [fixed-127.0.0.1_8848] [get-config] get from server error, dataId=nutzboot, group=DEFAULT_GROUP, tenant=, msg=ErrCode:500, ErrMsg:[NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached
16 回复

连不上参数服务器

服务器可以连接,只是程序没有去读取配置文件,用的默认参数

nacos为192.168.1.71 程序现在连的是127.0.0.1(默认参数)

 [NACOS ConnectException httpGet] currentServerAddr:http://127.0.0.1:8848, err : Connection refused (Connection refused)
server-addr

不是这个名字吧,打印配置手册看看

这个init方法,获取的conf是空的

package org.nutz.boot.starter.nacos;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import org.nutz.boot.AppContext;
import org.nutz.boot.annotation.PropDoc;
import org.nutz.boot.config.impl.AbstractConfigureLoader;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.stream.StringInputStream;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import java.io.IOException;
import java.util.Properties;

import static com.alibaba.nacos.api.PropertyKeyConst.*;

/**
 * @author wentao
 * @author wendal
 * @author wizzer
 * @email wentao0291@gmail.com
 * @email wendal1985@gmail.com
 * @email wizzer.cn@gmail.com
 * @date 2019-03-06 21:45
 */
@IocBean
public class NacosConfigureLoader extends AbstractConfigureLoader {
    /**
     * 获取日志对象
     */
    private static final Log log = Logs.get();
    /**
     * Nacos配置项前缀
     */
    protected static final String NACOS_PRE = "nacos.config.";
    /**
     * Nacos远程地址配置项
     */
    @PropDoc(value = "Nacos远程地址", defaultValue = "127.0.0.1:8848")
    public static final String NACOS_ADDR = NACOS_PRE + "server-addr";
    /**
     * Nacos Data ID 配置项
     */
    @PropDoc(value = "Nacos Data ID", defaultValue = "nutzboot")
    public static final String NACOS_DATA_ID = NACOS_PRE + "data-id";
    /**
     * Nacos分组配置项
     */
    @PropDoc(value = "Nacos分组", defaultValue = "DEFAULT_GROUP")
    public static final String NACOS_GROUP = NACOS_PRE + "group";
    /**
     * Nacos数据类型配置项(用于识别使用哪种方式解析配置项) 支持配置: json, properties, xml
     */
    @PropDoc(value = "Nacos 数据类型", defaultValue = "properties")
    public static final String NACOS_DATA_TYPE = NACOS_PRE + "data-type";

    @PropDoc(value = "Nacos 编码方式", defaultValue = "")
    public static final String NACOS_ENCODE = NACOS_PRE + "encode";

    @PropDoc(value = "Nacos 命名空间ID", defaultValue = "")
    public static final String NACOS_NAMESPACE = NACOS_PRE + "namespace";

    @PropDoc(value = "Nacos AccessKey", defaultValue = "")
    public static final String NACOS_ACCESS_KEY = NACOS_PRE + "access-key";

    @PropDoc(value = "Nacos SecretKey", defaultValue = "")
    public static final String NACOS_SECRET_KEY = NACOS_PRE + "secret-key";

    @PropDoc(value = "Nacos ContextPath", defaultValue = "")
    public static final String NACOS_CONTEXT_PATH = NACOS_PRE + "context-path";

    @PropDoc(value = "Nacos 集群名称", defaultValue = "")
    public static final String NACOS_CLUSTER_NAME = NACOS_PRE + "cluster-name";

    @PropDoc(value = "Nacos 最大重试次数", defaultValue = "")
    public static final String NACOS_MAX_RETRY = NACOS_PRE + "max-retry";

    @PropDoc(value = "Nacos 配置监听长轮询超时时间", defaultValue = "")
    public static final String NACOS_CONFIG_LONG_POLL_TIMEOUT = NACOS_PRE + "config-long-poll-timeout";

    @PropDoc(value = "Nacos 配置重试时间", defaultValue = "properties")
    public static final String NACOS_CONFIG_RETRY_TIME = NACOS_PRE + "config-retry-time";

    @PropDoc(value = "Nacos 启动时拉取配置", defaultValue = "false")
    public static final String NACOS_ENABLE_REMOTE_SYNC_CONFIG = NACOS_PRE + "enable-remote-sync-config";

    @PropDoc(value = "Nacos Endpoint", defaultValue = "properties")
    public static final String NACOS_ENCODE_ENDPOINT = NACOS_PRE + "endpoint";

    @Inject
    protected AppContext appContext;

    @Override
    public PropertiesProxy get() {
        return conf;
    }

    private void setConfig(String content, String contentType, PropertiesProxy conf) {
        if ("json".equals(contentType)) {
            NutMap configMap = new NutMap(content);
            conf.putAll(configMap);
        } else if ("xml".equals(contentType)) {
            Properties properties = new Properties();
            try {
                properties.loadFromXML(new StringInputStream(content));
                for (Object key : properties.keySet()) {
                    conf.put(key.toString(), properties.get(key).toString());
                }
            } catch (IOException e) {
                throw Lang.makeThrow("nacos config xml parse error!");
            }
        } else if ("properties".equals(contentType) || "txt".equals(contentType)) {
            PropertiesProxy propertiesProxy = new PropertiesProxy(new StringInputStream(content));
            conf.putAll(propertiesProxy);
        } else {
            throw Lang.makeThrow("nacos.config.data_type is not found or not recognize,only json,xml and properties are support!");
        }
    }

    @Override
    public void init() throws Exception {
        String dataId = conf.get(NACOS_DATA_ID, conf.get("nutz.application.name", "nutzboot"));
        String group = conf.get(NACOS_GROUP, "DEFAULT_GROUP");
        String dataType = conf.get(NACOS_DATA_TYPE, "properties");
        ConfigService configService = NacosFactory.createConfigService(getNacosConfigProperties());
        String configInfo = configService.getConfig(dataId, group, 5000);
        log.debugf("get nacos config:%s", configInfo);
        if (Strings.isNotBlank(configInfo)) {
            setConfig(configInfo, dataType, conf);
        }
    }

    public Properties getNacosConfigProperties() {
        Properties properties = new Properties();
        properties.put(SERVER_ADDR, conf.get(NACOS_ADDR, "127.0.0.1:8848"));
        properties.put(ENCODE, conf.get(NACOS_ENCODE, ""));
        properties.put(NAMESPACE, conf.get(NACOS_NAMESPACE, ""));
        properties.put(ACCESS_KEY, conf.get(NACOS_ACCESS_KEY, ""));
        properties.put(SECRET_KEY, conf.get(NACOS_SECRET_KEY, ""));
        properties.put(CONTEXT_PATH, conf.get(NACOS_CONTEXT_PATH, ""));
        properties.put(CLUSTER_NAME, conf.get(NACOS_CLUSTER_NAME, ""));
        properties.put(MAX_RETRY, conf.get(NACOS_MAX_RETRY, ""));
        properties.put(CONFIG_LONG_POLL_TIMEOUT,
                conf.get(NACOS_CONFIG_LONG_POLL_TIMEOUT, ""));
        properties.put(CONFIG_RETRY_TIME, conf.get(NACOS_CONFIG_RETRY_TIME, ""));
        properties.put(ENABLE_REMOTE_SYNC_CONFIG, conf.get(NACOS_ENABLE_REMOTE_SYNC_CONFIG, ""));
        String endpoint = conf.get(NACOS_ENCODE_ENDPOINT, "");
        if (endpoint.contains(":")) {
            int index = endpoint.indexOf(":");
            properties.put(ENDPOINT, endpoint.substring(0, index));
            properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
        } else {
            properties.put(ENDPOINT, endpoint);
        }
        return properties;
    }
}

  @Override
    public void init() throws Exception {
        String dataId = conf.get(NACOS_DATA_ID, conf.get("nutz.application.name", "nutzboot"));
  

不会吧,init方法里面conf为空??

是的,可惜图片没法上传。我有截图

哦, 待我查查

提交了一个修改,可以试试

这个也请改下

/**
 * @author wizzer(wizzer.cn)
 * @date 2020/1/8
 */
@IocBean
public class NacosDiscoveryLoader extends AbstractConfigureLoader {

好像不是一码事

我的意思这个NacosDiscoveryLoader也会遇到同样的问题

好呢, 改了一版

添加回复
请先登陆
回到顶部