使用 Spring MVC 为多个数据源配置 MyBatis

Configuring MyBatis with Spring MVC for multiple datasources

我一直在尝试使用 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>

根据异常:BadSqlGrammarException: ### Error querying database. Cause: java.sql.SQLException: ORA-06576: not a valid function or procedure name,命中了一个DB

阅读错误 ORA-06576

问题可能与程序的调用方式有关。正确的方法是 { CALL MyProcedure (#arg0, #arg1) }

配置显示相同的映射器可以用于两个数据源,如果目标模式不同会发生什么?