英文:
Spring boot is taking the default value instead of from application-local.yml
问题
我有一个类,它从配置文件中获取一个值,但它不起作用。
@Component
public class InputValidator {
private final Logger log = ESAPI.getLogger(this.getClass());
@Value("${apis.maxNumOfCics : 88}")
private Integer maxNumOfCics;
// 一些方法
}
我已经配置了一个随机的默认值88,尽管我在application-local.yml中将其配置为20,但它仍然被使用。当我不使用默认值时:
@Value("${apis.maxNumOfCics}")
它会从application-local.yml中获取正确的值,而且我也将活动配置文件设置为local。拼写是正确的,其他配置值都来自yml文件,但当我设置默认值时,它总是采用默认值。对此有任何帮助将不胜感激!
英文:
I have a class which takes a value from the config file but it is not working.
@Component
public class InputValidator {
private final Logger log = ESAPI.getLogger(this.getClass());
@Value("${apis.maxNumOfCics : 88}")
private Integer maxNumOfCics;
// some methods
}
I have configured a random default value of 88 which is being used even though I configured it as 20 in application-local.yml. When i don't use a default value:
@Value("${apis.maxNumOfCics}")
it takes the correct value from application-local.yml, and I set the the active profile to local as well. The spelling is correct and the other config values are coming from the yml file but when I put a default it always takes the default. Any help on this would be appreciated!
答案1
得分: 1
I think the problem is the spaces in the expression. Try removing the spaces in your expression before and after the :
.
@Value("${apis.maxNumOfCics:88}")
private Integer maxNumOfCics;
尝试移除表达式中冒号(:
)前后的空格。
尝试使用以下语法之一:https://www.baeldung.com/spring-value-annotation
英文:
I think the problem is the spaces in the expression. Try removing the spaces in your expression before and after the :
.
@Value("${apis.maxNumOfCics:88}")
private Integer maxNumOfCics;
Try one of the pieces of syntax from https://www.baeldung.com/spring-value-annotation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论