Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用了ConditionalOnProperty注解,Nacos配置了不起效,在本地properties文件没问题 #11235

Closed
feiren24 opened this issue Oct 9, 2023 · 3 comments
Labels
area/Spring Cloud Related to Spring Cloud status/invalid This doesn't seem right

Comments

@feiren24
Copy link

feiren24 commented Oct 9, 2023

@configuration
@ConditionalOnProperty(prefix = "yzw.fss",name = "address")
public class FastDFSAutoConfiguration {

protected final Logger logger = LoggerFactory.getLogger(this.getClass());

@Bean(name = "fastDFSClientWrapper")
public FastDFSClient getFastDFSClientWrapper() {
    FastDFSClient fastDFSClientWrapper = new FastDFSClient();
    logger.info("getFastDFSClientWrapper :{}", fastDFSClientWrapper);
    return fastDFSClientWrapper;
}

}
如果在本地properties文件配置了就能进行getFastDFSClientWrapper方法创建Bean,如果移到Nacos配置就不行,nacos配置是正常读取的,数据库其他中间件配置都能读取到,目前Nacos是不是不支持ConditionalOnProperty注解?
yzw.fss.address=https://fss-ext-qa.yzw.cn
#在文件存储服务中申请的应用标识。
yzw.fss.app.name=hello
#应用对应的密钥。
yzw.fss.app.secret=scTbUDPoAvGHtLlv69

@huangkemingyyds
Copy link
Contributor

应该是加载顺序的问题吧?Nacos有不支持ConditionalOnProperty注解这一说吗,如果真的有请艾特我一下。

@stone-98
Copy link
Contributor

stone-98 commented Oct 11, 2023

这应该不是Nacos的问题,应该是nacos-spring-boot的问题,应该是ConditionalOnProperty的生效时间在拉取配置之前。
相关issue:
nacos-group/nacos-spring-boot-project#300

@KomachiSion KomachiSion added status/invalid This doesn't seem right area/Spring Cloud Related to Spring Cloud labels Oct 11, 2023
@KomachiSion
Copy link
Collaborator

nacos是负责推送和管理远程配置的, 应用什么时候触发订阅和获取配置是由应用控制的, ConditionalOnProperty是应用测注解,需要应用测保证先从nacos获取配置并应用后再生效,并且需要在配置变更后进行重新加载等操作。

@KomachiSion KomachiSion closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Spring Cloud Related to Spring Cloud status/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants