控制应用@propertysource注释的顺序的正确方法是什么? 我的问题:我想为环境贡献属性。我可以使用EnvironmentPostProcessor来执行此操作,但我想使用@propertysource进行此操作,因为它更加了...

问题描述 投票:0回答:1
来做

@AutoConfiguration

,因为它更方便。
nove,似乎没有一种方法来描述应应用属性源的顺序。我尝试将它们放在
@AutoConfigureBefore
课上,并使用
@AutoConfigureAfter

@Configuration

。我尝试将它们放在普通的
@Configuration
课上,并从自动配置中导入
spring-core
。但是这些都没有产生可预见的顺序。
同样,代码本身在
addLast
'中添加了第一个使用
@PropertySource
看到的属性源,然后在此之前添加每个susequent源。请参阅下面的相关部分的图像屏幕截图:


this最终以一些奇怪的反向顺序从第一个看来,这使我更加困惑。
您可以建议在使用自动配置时如何实现订单?

根据当前春季(enter image description here6.2.4

javadoc

说:

In certain situations, it may not be possible or practical to tightly control property source ordering when using @PropertySource annotations. For example, if the @Configuration classes above were registered via component-scanning, the ordering is difficult to predict. In such cases — and if overriding is important — it is recommended that the user fall back to using the programmatic PropertySource API. See ConfigurableEnvironment and MutablePropertySources javadocs for details.

为了确定属性源的各自顺序,可以使用
spring spring-boot
1个回答
0
投票

addAfter

addBeforeaddFirst

方法。 不幸的是,似乎没有一种简单的方法来实现相应的订单,例如实现
addLast
接口。
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.