首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用spring-mybatis 1.2和spring 3.1.1多次调用存储过程时,web应用程序停止

使用spring-mybatis 1.2和spring 3.1.1多次调用存储过程时,web应用程序停止
EN

Stack Overflow用户
提问于 2019-07-02 15:26:39
回答 1查看 116关注 0票数 0

我尝试使用存储过程,但当我多次调用该过程时,web应用程序停止。它在打开JDBC连接时停止。mybatis-spring在insert语句中有问题吗?

我调用了更新表的存储过程,如果它找不到目标行,只需插入新行。但是,当我多次调用该过程时,web应用程序被暂停,并且所有的数据库连接都没有建立。我正在尝试更改db-context bean。但是,它仍然不起作用。

我的db-context.xml设置如下。

代码语言:javascript
复制
      -->                                                  
代码语言:javascript
复制
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
    <property name="dataSource" ref="repositoryDataSource" />
    <property name="configLocation" value="/WEB-INF/config/mybatis/mybatis-config.xml" />
    <property name="mapperLocations" value="/WEB-INF/config/mybatis/mapper/*.xml" />
    <property name="databaseIdProvider" ref="databaseIdProvider" />
</bean>

<bean id="vendorProperties"
    class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="properties">
        <props>
            <prop key="SQL Server">sqlserver</prop>
            <prop key="DB2">db2</prop>
            <prop key="Oracle">oracle</prop>
            <prop key="MySQL">mysql</prop>
        </props>
    </property>
</bean>

<bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider">
    <property name="properties" ref="vendorProperties" />
</bean>

<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

底部的日志是起作用的日志。

代码语言:javascript
复制
    DEBUG [org.mybatis.spring.SqlSessionUtils] Creating a new SqlSession 
    DEBUG [org.mybatis.spring.SqlSessionUtils] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d896e0a] was not registered for synchronization because synchronization is not active 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Opening JDBC Connection 
    DEBUG [org.mybatis.spring.SqlSessionUtils] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6d896e0a] 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Closing JDBC Connection [jdbc:sqlserver://serverIP:PORT;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=testDataBaseName;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;, UserName=user, Microsoft JDBC Driver 4.0 for SQL Server] 
    DEBUG [org.mybatis.spring.SqlSessionUtils] Creating a new SqlSession 
    DEBUG [org.mybatis.spring.SqlSessionUtils] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3d4bdd0f] was not registered for synchronization because synchronization is not active 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Opening JDBC Connection 
    DEBUG [Report.CALL_UP_SP] ==>  Preparing: {call CALL_UP_SP ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )}  
    DEBUG [Report.CALL_UP_SP] ==> Parameters: 0(Integer), 19277(String), saveName(String), 2261(String), PUBLIC(String), 370(String), someString(String), (String), (String), (String), (String), (String), (String), (String), someString(String), someString(String), someString(String), someString(String), PFBBUkFNX1hNTC8+(String), (String), 1000(String), N(String), N(String), (String), 1000(String), N(String) 
    DEBUG [Report.CALL_UP_SP] <==      Total: 1 
    DEBUG [org.mybatis.spring.SqlSessionUtils] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3d4bdd0f] 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Closing JDBC Connection [jdbc:sqlserver://serverIP:PORT;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=testDataBaseName;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;, UserName=user, Microsoft JDBC Driver 4.0 for SQL Server] 

我把它贴上了分解后的木头。

代码语言:javascript
复制
    DEBUG [org.mybatis.spring.SqlSessionUtils] Creating a new SqlSession 
    DEBUG [org.mybatis.spring.SqlSessionUtils] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@25f74881] was not registered for synchronization because synchronization is not active 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Opening JDBC Connection 
    DEBUG [org.mybatis.spring.SqlSessionUtils] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@25f74881] 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Closing JDBC Connection [jdbc:sqlserver://serverIP:PORT;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=testDataBaseName;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite;, UserName=user, Microsoft JDBC Driver 4.0 for SQL Server] 
    DEBUG [org.mybatis.spring.SqlSessionUtils] Creating a new SqlSession 
    DEBUG [org.mybatis.spring.SqlSessionUtils] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@18d75584] was not registered for synchronization because synchronization is not active 
    DEBUG [org.apache.ibatis.transaction.managed.ManagedTransaction] Opening JDBC Connection (--> web-application doesn't work after it)

如您所见,org.apache.ibatis.transaction.managed.ManagedTransaction正在打开JDBC连接,但之后它就不起作用了。因此,我尝试重新启动tomcat7,在eclipse控制台上显示以下日志。

代码语言:javascript
复制
    The web application [/test] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@14d49cb3]) and a value of type [org.apache.ibatis.executor.ErrorContext] (value [
    ### The error may exist in ServletContext resource [/WEB-INF/config/mybatis/mapper/test.xml]
    ### The error may involve test.CALL_UP_SP
    ### The error occurred while executing a query]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

有人知道这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2019-07-03 09:32:01

我找到问题了。这在调用过程中不是问题。在我的例子中,我必须处理各种DBMS。因此,我必须检查DBMS类型来处理它。但是,为了检查DBMS,我写下了如下代码。

代码语言:javascript
复制
DBMSName = super.getSqlSession().getConfiguration().getEnvironment().getDataSource().getConnection().getMetaData().getDatabaseProductName();
System.out.println("current DBMS type : "+DBMSName);

在这种情况下,我认为它会打开连接,直到web应用程序停止。因此,我删除了代码,它工作得很好。有人知道为什么会这样吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56847357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档