【发布时间】:2016-09-29 21:03:19
【问题描述】:
这可能是一个愚蠢的问题,但是否可以在 Spring Boot 中从 application.properties 文件中填充列表。这是一个简单的例子:
public class SomeClass {
@Value("${hermes.api.excluded.jwt}")
private List<String> excludePatterns = new ArrayList<>();
// getters/settings ....
}
application.properties
// Is something along these lines possible????
hermes.api.excluded.jwt[0]=/api/auth/
hermes.api.excluded.jwt[1]=/api/ss/
我知道我可以分解逗号分隔的字符串,但我只是好奇是否有原生的 spring boot 方法来做到这一点?
【问题讨论】:
-
你试过了吗?似乎尝试这个比写一个问题花费的时间更少:)
-
是的,如果可能的话我不知道属性文件中的秘密语法,我的问题只是使用了我认为很明显的东西,我得到....引起:org.springframework.beans .factory.BeanCreationException:无法自动装配字段:私有 java.util.List com.cwssoft.reportout.filter.JwtFilter.excludePatterns;嵌套异常是 java.lang.IllegalArgumentException:无法解析字符串值“${hermes.api.excluded.jwt}”中的占位符“hermes.api.excluded.jwt”
-
这令人惊讶,我原以为有一种更简洁的方法(与简单的 string.split 相比),因为它在 applicationContext 文件中很常见。谢谢
-
哦,github.com/spring-projects/spring-boot/issues/… 您不必拆分,现在在启动时显然已默认启用。 + YAML 似乎支持您的语法:docs.spring.io/spring-boot/docs/current/reference/html/…
标签: java spring spring-boot