问题:

环境 : Nacos 2.2.1 , Spring-cloud Hoxton.SR1 ,com.alibaba.cloud.version 2.2.8 (留意这个版本)

最近新搭建了一次虚拟机, 然后重新部署了Nacos , 同时也在一个新项目里引入了Nacos 的服务注册功能 , 以下是服务Pom版本管理配置

1.8UTF-8Hoxton.SR12.2.8.RELEASE org.springframework.bootspring-boot-dependencies2.2.2.RELEASEpomimportorg.springframework.cloudspring-cloud-dependencies${spring-cloud.version}pomimportcom.alibaba.cloudspring-cloud-alibaba-dependencies${com.alibaba.cloud.version}pomimport

然后再实际使用模块pom文件中引入服务注册和配置管理

com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloudspring-cloud-starter-alibaba-nacos-config

application.ymal 的配置如下

spring:profiles: devcloud:nacos:username: nacospassword: nacosdiscovery:server-addr: 192.168.30.128:8848namespace: 281222d0-6848-4017-8768-c81df219e12config:bootstrap:enabled: trueserver-addr: ${spring.cloud.nacos.discovery.server-addr}file-extension: ymlnamespace: 281222d0-6848-4017-8768-c81df219e12auto-refresh: true

此时启动项目问题就显露了 , 在没有加上spring-cloud-starter-alibaba-nacos-config 这个maven配置的时候服务是可以正常启动的 , 然后加了之后 服务根本就启动不起来 , 报错如下

2023-03-31 10:30:06.710 ERROR 40924 --- [ main]o.s.boot.SpringApplication: 826 : Application run failedjava.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/config.log" as that given for appender [CONFIG_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/naming.log" as that given for appender [NAMING_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/remote.log" as that given for appender [REMOTE_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/config.log" as that given for appender [CONFIG_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CONFIG_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/naming.log" as that given for appender [NAMING_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[NAMING_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - 'File' option has the same value "C:\Users\huang\logs/nacos/remote.log" as that given for appender [REMOTE_LOG_FILE] defined earlier.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - Collisions detected with FileAppender/RollingAppender instances defined earlier. Aborting.ERROR in ch.qos.logback.core.rolling.RollingFileAppender[REMOTE_LOG_FILE] - For more information, please visit http://logback.qos.ch/codes.html#earlier_fa_collisionat org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:313)at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:288)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)at com.ko.assy.db.ms.KoAssyDbApplication.main(KoAssyDbApplication.java:29)

看表象 , 是Logback 引起的问题 , 初步怀疑是可能因为冲突了 , 因为我本地也使用了 Logback 的配置 , Logbak内容入如下

logback<!---->DEBUG${CONSOLE_LOG_PATTERN}UTF-8${log.path}/web-all.log%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%15.15thread]%-40.40logger{39}:%4line: %msg%nUTF-8${log.path}/web-all-%d{yyyy-MM-dd}.%i.log100MB15${log.path}/web-trace.log%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%15.15thread]%-40.40logger{39}:%4line: %msg%nUTF-8${log.path}/web-trace-%d{yyyy-MM-dd}.%i.log100MB15${log.path}/web-warn.log%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%15.15thread]%-40.40logger{39}:%4line: %msg%nUTF-8${log.path}/web-warn-%d{yyyy-MM-dd}.%i.log100MB15WARNACCEPTDENY${log.path}/web-error.log%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%15.15thread]%-40.40logger{39}:%4line: %msg%nUTF-8${log.path}/web-error-%d{yyyy-MM-dd}.%i.log100MB15ERRORACCEPTDENY

问题排查解决

问题原因大概猜测是因为配置冲突引起的, 我就去看jar的内容 , 看看是nacos 的那个pom 再用logback , 最终在 nacos-config -> nacos-client 2.1.0 中发现了Logback 的配置文件

罪魁祸首找到了 , 那么久来处理掉这个冲突 , 最直接最简洁的方式就是 , 直接在config 的pom 中屏蔽掉他的nacos-client

com.alibaba.cloudspring-cloud-starter-alibaba-nacos-configcom.alibaba.nacosnacos-client

事实证明 , 无效,,,,,,, ,此路不通 ,,, 就换条路 , 去搜百度, 也是资料少的要死 , 索性直接去GitHub上找Nacos 仓库 找 issues , 抱着试一试的态度 , 万幸 , 找到了一个2022年6月份提交的一个bug

这个Issues 说得就是 nacos-logback 和 项目中的logback冲突 , 并且这位仁兄还放出了报错信息 , 看报错内容是不是眼熟 , 嗯哼 ” />

然后再次重启项目 , 豁然 启动了 , 为什么这样就可以了呢 ” />

从这里看 , client 的版本也更新了 ,

那么 , 试试呗, 升级项目中管理的 spring-cloud-alibaba-dependencies 版本 ,

Hoxton.SR1<!--2.2.8.RELEASE-->2022.0.0.0-RC1

果不其然, 出问题了 ,,,,,,真 tm X蛋 , 最新版本的nacos pom 居然是 jdk 17 , 我以为我11 都够新的了 , ,,,,,,,,, 搞到这里 , 如果大家不想继续搞了的话, 就用前面的解决办法 , 把scan 设置为 false , ,,, 什么治标不治本 , 先启动再说 ,,,,爱咋滴咋滴,,,,,,有时间再搞 ,

挣扎10分钟 , 决定还是不让这篇文章烂尾 , 决心要处理下

重新打开 mvn 中央仓库 , 大丈夫能屈能伸 , 退而求其次 , 选个 使用量多的 , 低一版的 , 2021.1

好奇看了一眼 , 这个nacos-client到底咋回事 , 点进去一看, 豁…. 好家活,,,

废话少说 , pom 再一次换版本 ,

Hoxton.SR1<!--2.2.8.RELEASE --><!--2022.0.0.0-RC1 -->2021.1

完美启动