【发布时间】:2018-08-09 15:10:20
【问题描述】:
我有一个应用程序(springboot 2),客户想要编辑整数值,它代表 AutoGrowCollectionLimit 的最大值。这个值默认(根据 springdocs)设置为 256,这对于我们的目的来说是不够的。
设置属性的代码:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit([configurable_number]);
}
这个值应该可以在配置文件中进行配置(比如说 some.txt),它将作为一个 txt 文件传递到应用程序旁边。现在将 some.txt 文件放在哪里都没有关系,现在即使是应用程序的 root 也可以。
这意味着,作为客户,我可以轻松更改它。打开 some.txt 文件并将值从 i.e.: 256 更改为 i.e.: 555.
在调查期间,我找到了this。但它不适合我的情况。我正在寻找的是 some.txt 文件中具有非常简单属性的配置,即:
AutoGrowCollectionLimit=[configurable_number]
根据springdocs,我尝试了以下:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(${set.max.collectionLimit});
}
并且还编辑了 [projectUrl]/src/main/resources/application.yml 如下:
set:
max:
collectionLimit: 500
当我尝试在以下位置调用此属性时,IDE 需要 ')' 或 '}':
binder.setAutoGrowCollectionLimit(${set.max.collectionLimit});
有人可以帮忙吗?
【问题讨论】:
-
这远非一个正确的问题。您应该从编写一些代码开始。
-
好的,我编辑了问题,现在更好了吗?
-
好多了,是的。在等待重新打开问题时,请查看 Spring Externalized Configuration 文档,特别是有关在类路径之外提供其他 .yml 或 .properties 文件的信息。
标签: java spring-boot configuration yaml