我有一个配置服务器和配置客户端,我已经将属性文件值注入到我的java类中,如下所示,
@RefreshScope
@Component
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties
@Getter
public class PropConig{
@Value("${welcome.message}")
private String message;
}
属性文件包含以下代码welcome.message = "Welcome to my app"
我有一个JMS配置类@AutoWired,其中PropConig如下所示,我使用了上述属性值
@EnableJms
@Log4j2
public class JmsConfig{
@AutoWired PropConig propConig;
-Here I am accessing the values using**propConig.message**
}
一切正常,但当我在PropConig.class中使用@RefreshScope时,在启动应用程序时出现错误。请帮助我。
1条答案
按热度按时间mspsb9vt1#
您可以使用配置属性并删除@value、@refreshScope
hostName的值是www.example.com中的sample.hostName或sample.host-name的值application.properties
参考文档:https://www.baeldung.com/configuration-properties-in-spring-boot