@Value アノテーションで if-then-else コンストラクトを評価する Spring SpEL に問題があります。
1. 私の config.xml ファイル:
<context:annotation-config />
<context:property-placeholder location="file://${HOME}/maven.props/${USER}.properties" properties-ref="props" />
<bean id="props" class="java.util.Properties">
<constructor-arg>
<props>
<prop key="interfaceName">createupdateproduct</prop>
<prop key="destImportFilesDirectoryPath">${batch.job.import.zipDestinationPath}/${interfaceName}/imported</prop>
<prop key="sourceImportFilesDirectoryPath">${batch.job.import.sourceImportPath}/${interfaceName}/import</prop>
<prop key="reportDirectoryPath">${batch.job.import.reportPath}/createupdateproduct/report</prop>
</props>
</constructor-arg>
</bean>
2. 私の Bean には、次のものがあります。
@Value("#{jobParameters['destFile']} ?: ${destImportFilesDirectoryPath}")
private String destImportFilesDirectoryPath;
質問。Bean jobParameters['destFile'] が null の場合、プレースホルダー値に切り替えたいと思います。jobParameters は、Spring Batch がコンテキストに入れる Bean です。
前のコード スニペットは正しく機能しませんが、 #{jobParameters['destFile']} と ${destImportFilesDirectoryPath} の両方が正しく評価されます:O
次のようなさまざまなソリューションを試します。
@Value("#{jobParameters['destFile']} != null ? #{jobParameters['destFile']} : ${destImportFilesDirectoryPath}")
また
@Value("#{ org.apache.commons.lang.StringUtils.isNotEmpty(#{jobParameters['destFile']}) ? #{jobParameters['destFile']} : ${destImportFilesDirectoryPath} }")
また
@Value("${ #{jobParameters['destFile']} ?: ${destImportFilesDirectoryPath} }")
しかし、何も正しく動作しません!