【问题标题】:Spring EL - split a property value and get the second entrySpring EL - 拆分属性值并获取第二个条目
【发布时间】:2016-01-09 08:53:34
【问题描述】:

我的属性中有以下属性

test.property=context:test:sample

我正在尝试通过与colon(:) 进行拆分并获取第二部分来检索值“test”。

我正在这样做:

@Value("#{'${test.property}'.split(':')[1]}")
private String test;

但是,它似乎以null 出现。我在做什么有问题吗?我在同一个文件中注入了其他属性,它们似乎可以毫无问题地读取。即使我只用@Value("${test.property}") 替换上面的表达式,它似乎也会读取字符串context:test:sample

【问题讨论】:

    标签: java spring properties spring-el


    【解决方案1】:

    你所拥有的对我来说很好用(我刚刚测试过);您的配置一定有其他问题。为org.springframework 开启 DEBUG 日志记录并观察所有注入处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 2019-03-09
      相关资源
      最近更新 更多