[英]Spring @Value annotation usage
Please see the code below.请看下面的代码。 Even though I set the spring.profiles.active=qa
it still overrides the last value which is dev-YAML
.即使我设置了spring.profiles.active=qa
它仍然覆盖最后一个值dev-YAML
。 Any idea why?知道为什么吗? I do not want to use @ConfigurationProperties
etc. I would like to use @Value
annotation.我不想使用@ConfigurationProperties
等。我想使用@Value
注释。
@Value("${name}")
private String name;
//application.yaml
spring:
profiles:
active: prod
name: prod-YAML
---
spring:
profiles:
active: qa
name: qa-YAML
---
spring:
profiles:
active: dev
name: dev-YAML
If you don't want to use @Configuration or @ConfigurationProperties, you have to move your configuration to other stereotypes such as @Service, @Controller, @RestController... classes如果不想使用@Configuration 或@ConfigurationProperties,则必须将配置移动到其他构造型,例如@Service、@Controller、@RestController... 类
@Value("${name}")
private String name;
Don't forget to activate your profile via arg -Dspring.profiles.active=active-profile
不要忘记通过 arg -Dspring.profiles.active=active-profile
激活您的个人-Dspring.profiles.active=active-profile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.