When applications based on struts2 and spring are idle for a period of time, a null pointer error is reported)

Source: Internet
Author: User

During struts2 and spring websites, after the system is idle for a period of time, an error will occur while accessing the page. The second visit will be normal. Later, I checked the background log and found that the database connection was closed, resulting in page access errors. A null pointer error is reported on the page. The error is not retained. The errors recorded in the log are as follows:

ERROR (java. SQL. Connection: 19)-Error calling Connection. close:
Java. SQL. SQLException: Already closed.
At org. apache. commons. dbcp. PoolableConnection. close (PoolableConnection. java: 84)
At org. apache. commons. dbcp. PoolingDataSource $ PoolGuardConnectionWrapper. close (PoolingDataSource. java: 181)
At org. springframework. jdbc. datasource. performanceutils. doReleaseConnection (performanceutils. java: 313)
At org. springframework. jdbc. datasource. transactionawareperformanceproxy $ TransactionAwareInvocationHandler. invoke (TransactionA
Wareperformanceproxy. java: 200)
At $ Proxy0.close (Unknown Source)
At sun. reflect. GeneratedMethodAccessor58.invoke (Unknown Source)
At sun. reflect. DelegatingMethodAccessorImpl. invoke (DelegatingMethodAccessorImpl. java: 25)
At java. lang. reflect. Method. invoke (Method. java: 585)
At com. ibatis. common. jdbc. logging. ConnectionLogProxy. invoke (ConnectionLogProxy. java: 68)
At $ Proxy1.close (Unknown Source)
At com. ibatis. sqlmap. engine. transaction. external. ExternalTransaction. close (ExternalTransaction. java: 82)
At com. ibatis. sqlmap. engine. transaction. TransactionManager. end (TransactionManager. java: 111)
At com. ibatis. sqlmap. engine. impl. SqlMapExecutorDelegate. endTransaction (SqlMapExecutorDelegate. java: 782)
At com. ibatis. sqlmap. engine. impl. SqlMapSessionImpl. endTransaction (SqlMapSessionImpl. java: 176)
At com. ibatis. sqlmap. engine. impl. SqlMapClientImpl. endTransaction (SqlMapClientImpl. java: 154)
At com. ibatis. sqlmap. engine. impl. SqlMapExecutorDelegate. autoEndTransaction (SqlMapExecutorDelegate. java: 883)
At com. ibatis. sqlmap. engine. impl. SqlMapExecutorDelegate. queryForList (SqlMapExecutorDelegate. java: 622)
At com. ibatis. sqlmap. engine. impl. SqlMapExecutorDelegate. queryForList (SqlMapExecutorDelegate. java: 589)
At com. ibatis. sqlmap. engine. impl. SqlMapSessionImpl. queryForList (SqlMapSessionImpl. java: 118)
At com. ibatis. sqlmap. engine. impl. SqlMapClientImpl. queryForList (SqlMapClientImpl. java: 95)
At com. wangar. ptc. dao. ibatis. IbatisSysMenuDAO. querySysMenuList (IbatisSysMenuDAO. java: 50)
At com. wangar. ptc. dao. impl. DefaultSysMenuDAO. querySysMenuList (DefaultSysMenuDAO. java: 22)
At com. wangar. ptc. manager. impl. DefaultSysMenuManager. querySysMenuList (defasyssysmenumanager. java: 187)
At com. wangar. ptc. manager. impl. DefaultSysMenuManager. querySysMenuBySmid (defasyssysmenumanager. java: 146)
At com. wangar. ptc. manager. impl. DefaultSysMenuManager. getRootSysMenu (defasyssysmenumanager. java: 90)
At com. wangar. ptc. ao. impl. DefaultSysMenuAO. getRootSysMenu (DefaultSysMenuAO. java: 50)
At com. wangar. ptc. action. IndexAction. mainIndex (IndexAction. java: 26)
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: 585)
At com. opensymphony. xwork2.defaactionactioninvocation. invokeAction (DefaultActionInvocation. java: 441)
At com. opensymphony. xwork2.DefaultActionInvocation. invokeActionOnly (DefaultActionInvocation. java: 280)
At com. opensymphony. xwork2.defaactionactioninvocation. invoke (defaactionactioninvocation. java: 243)
At com. opensymphony. xwork2.interceptor. DefaultWorkflowInterceptor. doIntercept (defaworkworkflowinterceptor. java: 165)
At com. opensymphony. xwork2.interceptor. MethodFilterInterceptor. intercept (MethodFilterInterceptor. java: 87)
At com. opensymphony. xwork2.defaactionactioninvocation. invoke (defaactionactioninvocation. java: 237)
At com. opensymphony. xwork2.validator. ValidationInterceptor. doIntercept (ValidationInterceptor. java: 252)
At org. apache. struts2.interceptor. validation. AnnotationValidationInterceptor. doIntercept (AnnotationValidationInterceptor. jav
A: 68)

...... Omitting some errors ......

When I saw the error, I thought it was because the data connection was not used for a long time and I closed it myself. So I first thought of starting with the data source configuration parameters, and then I searched for it, I see someone has encountered the same problem. I will post the content here first. I used apache dbcp data in spring for database connection. The configuration code is as follows:

Jdbc. driver = com. mysql. jdbc. Driver
Jdbc. url = jdbc: mysql: // localhost: 3306/database
Jdbc. username = user
Jdbc. password = usr
Data source configuration
<Bean id = "dataSource" class = "org. apache. commons. dbcp. BasicDataSource">
<Property name = "driverClassName" value = "$ {jdbc. driver}"/>
<Property name = "url" value = "$ {jdbc. url}"/>
<Property name = "username" value = "$ {jdbc. username}"/>
<Property name = "password" value = "$ {jdbc. password}"/>
</Bean>


# Verify the connection
Jdbc. testOnBorrow = true



The blue bold part mainly solves the problem of automatic database reconnection.

Original article: http://blog.sina.com.cn/s/blog_655c5e7b0100h9iu.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.