fix: NacosMetadataConfig添加@ConditionalOnBean避免Gateway加载失败

NacosMetadataConfig仅在Registration bean存在时生效,
解决Gateway等不需要服务注册的场景无法启动的问题
This commit is contained in:
zhangjf 2026-02-20 18:15:20 +08:00
parent 4af7d712cd
commit a78ccaeae5
8 changed files with 16 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri Feb 20 17:27:25 CST 2026
#Fri Feb 20 18:12:34 CST 2026
fund-common-0.0.1-SNAPSHOT.jar>=
fund-common-0.0.1-SNAPSHOT.pom>=

View File

@ -3,7 +3,7 @@
<groupId>com.fundplatform</groupId>
<artifactId>fund-common</artifactId>
<versioning>
<lastUpdated>20260220092715</lastUpdated>
<lastUpdated>20260220101230</lastUpdated>
<snapshot>
<localCopy>true</localCopy>
</snapshot>
@ -11,12 +11,12 @@
<snapshotVersion>
<extension>pom</extension>
<value>0.0.1-SNAPSHOT</value>
<updated>20260220092715</updated>
<updated>20260220101230</updated>
</snapshotVersion>
<snapshotVersion>
<extension>jar</extension>
<value>0.0.1-SNAPSHOT</value>
<updated>20260220092715</updated>
<updated>20260220101230</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>

View File

@ -6,6 +6,6 @@
<versions>
<version>0.0.1-SNAPSHOT</version>
</versions>
<lastUpdated>20260220092715</lastUpdated>
<lastUpdated>20260220101230</lastUpdated>
</versioning>
</metadata>

View File

@ -1,3 +1,3 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri Feb 20 17:13:04 CST 2026
#Fri Feb 20 18:12:31 CST 2026
fundplatform-0.0.1-SNAPSHOT.pom>=

View File

@ -3,7 +3,7 @@
<groupId>com.fundplatform</groupId>
<artifactId>fundplatform</artifactId>
<versioning>
<lastUpdated>20260220091303</lastUpdated>
<lastUpdated>20260220101230</lastUpdated>
<snapshot>
<localCopy>true</localCopy>
</snapshot>
@ -11,7 +11,7 @@
<snapshotVersion>
<extension>pom</extension>
<value>0.0.1-SNAPSHOT</value>
<updated>20260220091303</updated>
<updated>20260220101230</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>

View File

@ -6,6 +6,6 @@
<versions>
<version>0.0.1-SNAPSHOT</version>
</versions>
<lastUpdated>20260220091303</lastUpdated>
<lastUpdated>20260220101230</lastUpdated>
</versioning>
</metadata>

View File

@ -2,7 +2,9 @@ package com.fundplatform.common.nacos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.context.annotation.Configuration;
@ -29,8 +31,12 @@ import java.util.Map;
* # 方式2: 配置文件
* spring.cloud.nacos.discovery.metadata.tenant-id=VIP_001
* </pre>
*
* <p>注意此配置仅在 Registration Bean 存在时生效普通微服务
* Gateway 等不需要服务注册的场景不会加载此类</p>
*/
@Configuration
@ConditionalOnBean(Registration.class)
@ConditionalOnProperty(name = "tenant.routing.enabled", havingValue = "true", matchIfMissing = true)
public class NacosMetadataConfig {
@ -48,6 +54,7 @@ public class NacosMetadataConfig {
private final Registration registration;
@Autowired
public NacosMetadataConfig(Registration registration) {
this.registration = registration;
}