【发布时间】:2018-10-23 19:33:33
【问题描述】:
我不知道这是否与集成相关,但在我的上下文中,我尝试通过包含空格的键来引用有效负载值:
<int-jdbc:outbound-channel-adapter
query="INSERT INTO table (serial, dealer_code) VALUES (:payload[SERIES], :payload[DEALER CODE])"
data-source="dbDataSource">
</int-jdbc:outbound-channel-adapter>
虽然:payload[SERIES] 参数有效,但只要我不添加第二个:
:payload[DEALER CODE]:payload['DEALER CODE']:payload[&quot;DEALER CODE&quot;]
工作,而且最后两个用 a: 打断
org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'payload[': Invalid property 'payload[' of bean class [org.springframework.messaging.support.GenericMessage]: Bean property 'payload[' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
在其他地方,在另一个 enpoint 配置中,我确实使用引号:
<int-http:inbound-channel-adapter id="/api/requests"
...
status-code-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.method.equals('POST') ? 201 : 200">
</int-http:inbound-channel-adapter>
我已经解决了这个问题,添加了一个ExpressionEvaluatingSqlParameterSourceFactory(如Inbound Channel Adapter 中所述):
<int-jdbc:outbound-channel-adapter
query="INSERT INTO table (serial, dealer_code) VALUES (:serial, :dealerCode)"
sql-parameter-source-factory="spelSource"
data-source="dbDataSource">
</int-jdbc:outbound-channel-adapter>
<bean id="spelSource"
class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
<property name="parameterExpressions">
<map>
<entry key="serial" value="payload['SERIES']"/>
<entry key="dealerCode" value="payload['DEALER CODE']"/>
</map>
</property>
</bean>
</int-jdbc:outbound-channel-adapter>
但是由于负载字段只是被读取,这似乎太多了。
我在这里使用了错误的语法吗?
【问题讨论】:
标签: xml spring spring-integration