存储过程出站网关空参数处理 [英] Stored proc outbound gateway null parameter handling

查看:31
本文介绍了存储过程出站网关空参数处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使payload.second 为空(可选参数),我如何使此代码工作.

How can i make this code work even if payload.second is null (optional parameter).

<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

推荐答案

感谢您提供 StackTrace.当你不能拥有参数时,我只看到一个地方 - ExpressionEvaluatingSqlParameterSourceFactory:

Thank you for the StackTrace. Looking into that I see only the single place when you can't have the parameter - 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 的情况下发生.

The CallMetaDataContext#matchInParameterValuesWithCallParameters can't populate the second parameter because that hasValue() returns false. And this happens only in case of an ExpressionException.

打开 org.springframework.integration.jdbc 类别的 DEBUG 日志记录,您就会明白原因.

Switch on DEBUG logging for the org.springframework.integration.jdbc category and you'll the reason.

我猜你在这里只展示了简单的表达式 (payload.second) 表示不会使这个 SO 问题复杂化.

I guess you show here just only the simple expression (payload.second) representation do not complicate this SO question.

这篇关于存储过程出站网关空参数处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆