0

Spring Batch:如果键是从输入参数动态生成的,如何从属性文件中获取值

属性文件内容:my.table.book.bic.code=11111 my.table.news.bic.code=22222

Spring批处理配置

<property name="bicCodeValue" value="#{jobParameters['inputTable'] + '.bic.code'}" />

其中 inputTable 是批量 inputTable = my.table.book inputTable = my.table.news的输入参数

我没有从属性文件中获取值,而不是从属性文件中获取值我只获取代码“my.table.book.bic.code”中的键。

我只需要在 xml 文件中更新,例如

<property name="bicCodeValue" value="#{jobParameters['inputTable'] + '.bic.code'}" />

但这不起作用。

4

2 回答 2

0

你可以注入一个实例

@Autowired
private Environment env;

然后执行以下操作:

env.getProperty("my.table."+inputTable+".book.bic.code")
于 2018-07-11T07:54:29.723 回答
0

根据您的属性,SpEL 表达式jobParameters['inputTable']应该返回一个String值,因此您可以尝试concat在表达式中使用该方法:

<property name="bicCodeValue" value="#{jobParameters['inputTable'].concat('.bic.code')}" />

有关 SpEL 的更多详细信息,请参见此处:https ://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions

于 2018-07-11T12:47:22.307 回答