gpt4 book ai didi

java - 使用配置服务器解析 Spring Boot 应用程序中的占位符时出错

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:28 25 4
gpt4 key购买 nike

我正在配置配置服务器以在 springboot 应用程序中使用该应用程序最近已从 spring 迁移到 springboot,因此大部分属性都在 applicationContext.xml 文件中使用

示例:

<bean id="rabbitConnectionFactory"  class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">      
<property name="address" value="${rabbitmq.address}"/>
</bean>

This throw an IllegalArgumentException : Could not resolve placeholder

我还有配置属性文件来按前缀加载一些属性,如果我在下面的类中声明它们,我就可以使用我的属性:

@Configuration
@ConfigurationProperties
public class ConfiguationProperties {}

但是我不想将所有属性放在配置属性文件中并让我的 applicationContext 使用占位符语法直接加载属性,有可能吗?

最佳答案

我的错误是配置文件的路径不正确,因为我的属性文件位于配置路径 ${config-path}/subdirectory/myapplication-dev.properties 的子目录中

我删除了子目录,它工作正常。看来配置服务器只有在遵循 schema url 时才会正确加载类路径中的属性文件:

 http://localhost:8888/${my-profile}/myapplication

而不是:

http://localhost:8888/subdirectory/${my-profile}/myapplication

(如果我可以使用此网址在网络浏览器中查看我的属性,则发生事件)

关于java - 使用配置服务器解析 Spring Boot 应用程序中的占位符时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53930810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com