2013-02-27 32 views
1

我正嘗試複製和PostgreSQL到Oracle彈簧集成存儲過程咖啡的例子。沒有成功。 這裏是鏈接到原始代碼 https://github.com/SpringSource/spring-integration-samples/tree/master/intermediate/stored-procedures-postgresqlSpring集成+ oracle的存儲過程

我決定開始與剛纔的程序來獲取所有的咖啡,所以我刪除對getCoffee所有引用的名字在項目中。

下面是代碼到我的存儲過程:

create or replace 
PROCEDURE find_all_coffee_beverages AS 
begin 
    for x in (SELECT id, coffee_name, 
       coffee_description 
       FROM coffee_beverages 
       ORDER BY ID) loop 
     dbms_output.put_line 
      (x.coffee_description); 
    end loop; 
end; 

這裏是我的Spring上下文:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc" 
    xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
     http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" 
     destroy-method="close"> 
     <property name="connectionCachingEnabled" value="true" /> 
     <property name="URL" value="jdbc:oracle:thin:@//localhost:1521/XE" /> 
     <property name="password" value="admin" /> 
     <property name="user" value="admin" /> 
     <property name="connectionCacheProperties"> 
      <props merge="default"> 
       <prop key="MinLimit">3</prop> 
       <prop key="MaxLimit">20</prop> 
      </props> 
     </property> 
    </bean> 

    <int:channel id="findAllProcedureRequestChannel" /> 

    <int:gateway id="gateway" default-request-timeout="4000" 
     default-reply-timeout="4000" 
     service-interface="org.springframework.integration.service.CoffeeService"> 
     <int:method name="findAllCoffeeBeverages" request-channel="findAllProcedureRequestChannel" /> 
    </int:gateway> 

    <int-jdbc:stored-proc-outbound-gateway 
     id="outbound-gateway-storedproc-find-all" data-source="dataSource" 
     ignore-column-meta-data="true" request-channel="findAllProcedureRequestChannel" 
     expect-single-result="true" stored-procedure-name="FIND_ALL_COFFEE_BEVERAGES"> 
     <int-jdbc:returning-resultset name="ref" 
      row-mapper="org.springframework.integration.support.CoffeBeverageMapper" /> 
    </int-jdbc:stored-proc-outbound-gateway> 

    <bean id="transactionManager" 
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 

    <int:poller default="true" fixed-rate="5000"> 
     <int:transactional /> 
    </int:poller> 

</beans> 

所以我編譯它,像這樣的maven運行:MVN清潔套裝EXEC: java -e 它編譯完美,但是當它試圖運行時,我得到下一個例外:

--- exec-maven-plugin:1.2:java (default-cli) @ oracle-stored-procedures --- 
org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call FIND_ALL_COFFEE_BEVERAGES(?)}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7: 
PLS-00306: wrong number or types of arguments in call to 'FIND_ALL_COFFEE_BEVERAGES' 
ORA-06550: line 1, column 7: 
PL/SQL: Statement ignored 

    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233) 
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) 
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1030) 
    at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1064) 
    at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:388)14:01:56.804 WARN [org.springframework.integration.Main.main()][org.springframework.integration.gateway.GatewayProxyFactoryBean$MethodInvocationGateway] failure occurred in gateway sendAndReceive 
org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.jdbc.StoredProcOutboundGateway#0] 
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79) 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115) 
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102) 
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) 
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157) 
    at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288) 
    at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318) 
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239) 
    at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:274) 
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:224) 
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:203) 
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:306) 
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:269) 
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:260) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
    at $Proxy16.findAllCoffeeBeverages(Unknown Source) 
    at org.springframework.integration.Main.main(Main.java:67) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:291) 
    at java.lang.Thread.run(Thread.java:662) 

有誰知道我爲什麼會得到這些異常? 在此先感謝。

+0

'糟糕的SQL語法[{(?)調用FIND_ALL_COFFEE_BEVERAGES}]'在我看來像Spring試圖調用的程序有一個參數,但由於你的過程實際上沒有任何參數,我不確定它爲什麼這樣做。 – FrustratedWithFormsDesigner 2013-02-27 20:21:48

+0

有沒有人有一個彈簧集成的例子,它稱之爲商店程序? – linker85 2013-02-27 21:06:40

回答