2017-05-05 120 views
0

我一直在嘗試使用Spring MVC配置MyBatis以使用多個數據庫。我有一個頁面正試圖連接到其中一個數據庫來獲取數據,以便它可以填充到下拉框中。使用Spring MVC配置MyBatis以獲得多個數據源

現在我不知道什麼是錯的這個配置,但我收到以下錯誤:

]] Root cause of ServletException. org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLException: ORA-06576: not a valid function or procedure name 

我在這裏提供的XML文件,供您參考

<bean id="dataSource1" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
     <property name="url" value="jdbc:oracle:thin:@1.1.2.5:1529:DITOS" /> 
     <property name="username" value="return" /> 
     <property name="password" value="return" /> 
    </bean> 

    <!-- scan for mappers and let them be autowired --> 
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
     <property name="basePackage" 
      value="p.com.ent.appl.return.dev.dao,p.com.ent.appl.return.dep.dao,p.com.ent.appl.return.dao.otheruser" /> 
     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory1" /> 
    </bean> 


    <!-- Declare a transaction manager --> 
    <bean id="cashReturnTx" 
     class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
     <property name="dataSource" ref="dataSource1" /> 
    </bean> 

    <!-- define the SqlSessionFactory, notice that configLocation is not needed 
     when you use MapperFactoryBean --> 
    <bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource1" /> 
     <property name="configLocation" value="WEB-INF/mybatis/sqlmap-config.xml" /> 
     <!-- <property name="mapperLocations" value="classpath:/com/vrn/ent/dev/daoxml/*.xml" 
      /> --> 
     <property name="mapperLocations" 
      value="classpath*:/p/com/ent/appl/return/**/daoxml/*.xml" /> 
    </bean> 


    <bean id="sqlSession1" class="org.mybatis.spring.SqlSessionTemplate"> 
     <constructor-arg index="0" ref="sqlSessionFactory1" /> 
    </bean> 

    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
     <property name="url" value="jdbc:oracle:thin:@4.24.80.15:1522:LM" /> 
     <property name="username" value="RETURN" /> 
     <property name="password" value="OWNER" /> 
    </bean> 

<!-- scan for mappers and let them be autowired --> 
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
     <property name="basePackage" 
      value="p.com.ent.appl.return.dev.dao,p.com.ent.appl.return.dep.dao,p.com.ent.appl.return.dao.otheruser" /> 
     <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> 
    </bean> 

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


    <!-- define the SqlSessionFactory, notice that configLocation is not needed 
     when you use MapperFactoryBean --> 
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation" value="WEB-INF/mybatis/sqlmap-config.xml" /> 
     <!-- <property name="mapperLocations" value="classpath:/com/vrn/ent/dev/daoxml/*.xml" 
      /> --> 
     <property name="mapperLocations" 
      value="classpath*:/p/com/ent/appl/return/**/daoxml/*.xml" /> 
    </bean> 

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> 
     <constructor-arg index="0" ref="sqlSessionFactory" /> 
    </bean> 
</beans> 
+0

我們解決了它。實際問題是屬性名稱=「mapperLocations」。我們在這裏給出了相同的位置。但是我們改變了地理位置,並且對於它所運行的兩個數據源都有所不同。 – Shiva1281969

回答

1

根據例外:BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLException: ORA-06576: not a valid function or procedure name,數據庫被擊中。

閱讀關於錯誤ORA-06576

問題與調用過程的方式有關。正確的方法是{ CALL MyProcedure (#arg0, #arg1) }

配置顯示相同的映射器可能與兩個數據源一起使用,如果目標模式不同,會發生什麼情況?