2010-09-20 74 views
0

我正在使用數據源來記錄每個用戶請求的審計信息。 bean在初始化期間的springContext.xml中定義。爲Spring JDBC處理DataAccessException

每當數據庫關閉時,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) 

回答

0

如果您還沒有,則需要使審計bean lazy-init防止它在初始化期間實際嘗試調用數據庫。

在您的過濾器代碼中,圍繞審覈調用放置try/catch,以便您可以調用鏈中的下一個過濾器。

如果這無助於您的Spring配置的示例以及如何調用您的審計bean將有所幫助。