-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
SpringCloud项目中注解方式使用客户端导致Spring启动失败 #990
Comments
|
我把报错的代码弄出来了,是最精简的环境,希望有人能够帮助我看一下是什么原因导致 |
已经解决。原因是项目在XML中配置了自定义的property-placeholder,会创建的PropertySourcesPlaceholderConfigurer,但Apollo Client在此之前抢先创建了这个Bean,但没能读取到这里的配置,导致给Bean填充Value的时候,失败了。详细内容请访问上面的链接。 |
@slankka 非常感谢详细的分析。 由于Apollo的Spring使用方式依赖于PropertySourcesPlaceholderConfigurer,所以我们需要确保至少存在一个PropertySourcesPlaceholderConfigurer,这也是我们默认添加一个的原因。 我们后续看下是否可以把默认添加的这个PropertySourcesPlaceholderConfigurer的优先级调到最低,从而避免和用户的配置产生冲突。 |
Apollo 创建的PropertySourcesPlaceholderConfigurer中 ignoreUnresolvablePlaceholders 默认是true,导致只要没有配置值的,项目也不能启动成功。 |
Apollo 创建的PropertySourcesPlaceholderConfigurer没有设置ignoreUnresolvablePlaceholders这个属性,看了下Spring代码里面默认值是false呀,org.springframework.beans.factory.config.PlaceholderConfigurerSupport#ignoreUnresolvablePlaceholders |
不好意思,这个不是Apollo的问题。。另外优先级也不是Apollo的问题,只是需要说明一下,优先级默认刚好是int 最大值,都是最低的,需要用户自己提升优先级。 |
恩,刚看了一下,确实order已经是最低了 - Ordered.LOWEST_PRECEDENCE |
我现在用的1.2.1版本,我也遇到了这个问题,apollo在后面迭代中硬编码方式把PropertySourcesPlaceholderConfigurer优先级设为了0而不是注解中的最低,导致自定义的PropertySourcesPlaceholderConfigurer在后面加载,所以填充value报错。目前解决方法是把自定义的order设为-1 |
现在解决了吗,我好想也遇到相同的问题 |
@xiehanghang 项目中,最多配置一个 PropertySourcesPlaceholderConfigurer。因此要么把自定义配置的文件按照Spring Boot的规范放置, 参见SpringBoot官方文档,文件名和路径都要按照规范; 要么自己加载Yaml配置文件, 另外,如果你一定要自己亲手加载配置文件,这里给出我当时的临时解决方案仅供参考 |
大神们好,我在SpringCloud(Spring core 4.2.6)中 使用Apollo Client,选用
使用Spring Annotation支持
这个方式启动失败,报错如下,还有一些Value注解的配置注入失败的信息没有贴出来。
如果我用
删除
并且application配置文件指定
apollo.bootstrap.enabled: true
则可以启动成功。问题:
The text was updated successfully, but these errors were encountered: