即使payload.second为null(可选参数),如何使此代码正常工作。
<int-jdbc:stored-proc-outbound-gateway id="outGtw"
data-source="someDs"
request-channel="someChannel"
reply-channel="someOtherChannel"
stored-procedure-name="someStoredProcedure"
ignore-column-meta-data="true">
<int-jdbc:sql-parameter-definition name="first"/>
<int-jdbc:sql-parameter-definition name="second"/>
<int-jdbc:sql-parameter-definition name="outParam" direction="OUT" type="NVARCHAR"/>
<int-jdbc:parameter name="first" expression="payload.first"/>
<int-jdbc:parameter name="second" expression="payload.second"/>
</int-jdbc:stored-proc-outbound-gateway>
这是null
-
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Required input parameter 'second' is missing
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:211) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1115) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1173) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:381) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:342) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:190) ~[spring-jdbc-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.integration.jdbc.StoredProcExecutor.executeStoredProcedureInternal(StoredProcExecutor.java:328) ~[spring-integration-jdbc-4.0.4.RELEASE.jar:na]
at org.springframework.integration.jdbc.StoredProcExecutor.executeStoredProcedure(StoredProcExecutor.java:297) ~[spring-integration-jdbc-4.0.4.RELEASE.jar:na]
at org.springframework.integration.jdbc.StoredProcOutboundGateway.handleRequestMessage(StoredProcOutboundGateway.java:60) ~[spring-integration-jdbc-4.0.4.RELEASE.jar:na]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler.handleRequestMessage(AbstractReplyProducingMessageHandler.java:313) ~[spring-integration-core-4.0.4.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_31]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_31]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice$1.cloneAndExecute(AbstractRequestHandlerAdvice.java:92) ~[spring-integration-core-4.0.4.RELEASE.jar:na]
at org.springframework.integration.handler.advice.RequestHandlerRetryAdvice$2.doWithRetry(RequestHandlerRetryAdvice.java:88) ~[spring-integration-core-4.0.4.RELEASE.jar:na]
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:263) ~[spring-retry-1.1.1.RELEASE.jar:na]
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:193) ~[spring-retry-1.1.1.RELEASE.jar:na]
at org.springframework.integration.handler.advice.RequestHandlerRetryAdvice.doInvoke(RequestHandlerRetryAdvice.java:85) ~[spring-integration-core-4.0.4.RELEASE.jar:na]
... 88 common frames omitted
答案 0 :(得分:1)
感谢StackTrace。调查一下,当您无法获得参数时,我只会看到一个地方 - ExpressionEvaluatingSqlParameterSourceFactory
:
public boolean hasValue(String paramName) {
try {
Object value = doGetValue(paramName, true);
if (value == ERROR) {
return false;
}
}
catch (ExpressionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Could not evaluate expression", e);
}
if (this.cache) {
values.put(paramName, ERROR);
}
return false;
}
return true;
}
CallMetaDataContext#matchInParameterValuesWithCallParameters
无法填充second
参数,因为hasValue()
会返回false
。
这只发生在ExpressionException
。
启用DEBUG
类别的org.springframework.integration.jdbc
日志记录,您了解原因。
我想你在这里只展示了简单的表达式(payload.second
)表示并不会使这个问题复杂化。