处理Spring JDBC的DataAccessException

时间:2010-09-20 11:23:34

标签: database spring jdbc exception-handling datasource

我正在使用数据源按用户请求记录审核信息。 bean在初始化期间源自springContext.xml中定义。

每当数据库关闭时,bean初始化都会失败并出现以下错误:DataAccessException。

我想要做的是在此异常之后继续(因为没有能够记录)。 我该如何处理这种情况?

Error 500--Internal Server Error
Error creating bean with name 'AuditLogSequenceFactory' defined in ServletContext resource [/WEB-INF/AuditTrailContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.String org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextStringValue() throws org.springframework.dao.DataAccessException] threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool Simple/Datasource/Local is disabled, cannot allocate resources to applications.. - action - zip:C:/bea/user_projects/domains/Simple/./servers/AdminServer/tmp/_WL_user/simpleWN/j5vygk/war/WEB-INF/lib/_wl_cls_gen.jar!/struts_global.xml:9:60
 at com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:199)
 ....
    weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1880)
 at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1310)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AuditLogSequenceFactory' defined in ServletContext resource [/WEB-INF/AuditTrailContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.String org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextStringValue() throws org.springframework.dao.DataAccessException] threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool Simple/Datasource/Local is disabled, cannot allocate resources to applications..
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:442)
    ....
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3151)

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.String org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextStringValue() throws org.springframework.dao.DataAccessException] threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool Simple/Datasource/Local is disabled, cannot allocate resources to applications..
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)
    .... 
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
    Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool Simple/Datasource/Local is disabled, cannot allocate resources to applications..
 at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    .... at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)

Caused by: java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceDisabledException: Pool Simple/Datasource/Local is disabled, cannot allocate resources to applications..
 at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1295)
 at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:436)
 at weblogic.jdbc.jta.DataSource.connect(DataSource.java:392)
 at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:359)
    .... at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:126)

1 个答案:

答案 0 :(得分:0)

如果您还没有,则需要使用审计bean lazy-init来防止它在初始化期间实际尝试调用数据库。

在您的过滤器代码中,将try / catch放在审核调用周围,以便您可以调用链中的下一个过滤器。

如果这对您的Spring配置示例以及如何调用审计bean有帮助,那么这将无济于事。