알 수 없는 이유로 일부 SQL이 차단된 경우 백그라운드 서비스 실행에 영향을 주지 않기 위해 SQL에 실행 시간 제한을 추가하고 시간 초과 후 예외를 발생시켜 백그라운드 스레드가 중단되지 않도록 하려고 합니다. SQL 혼잡으로 인해 차단되었습니다.
단일 데이터 소스는 괜찮지만 여러 데이터 소스를 사용하면 실패합니다.
에서 시간 초과 예외가 발생했습니다.
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import javax.sql.DataSource; @Configuration @MapperScan(basePackages = "top.oldmoon.bill.mapper", sqlSessionFactoryRef = "sqlSessionFactory") public class DBConfiguration { @Primary @Bean(name = "dataSource") @ConfigurationProperties(prefix = "spring.datasource") public DataSource gfDataSource() { DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); return dataSource; } @Primary @Bean(name = "sqlSessionFactory") public SqlSessionFactory gfSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean(); factoryBean.setDataSource(dataSource); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/*.xml")); org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration(); configuration.setDefaultStatementTimeout(1); // 设置sql执行超时时间::(秒) factoryBean.setConfiguration(configuration); SqlSessionFactory sqlSessionFactory = factoryBean.getObject(); return sqlSessionFactory; } @Primary @Bean(name = "transactionManager") public DataSourceTransactionManager gfTransactionManager(@Qualifier("dataSource") DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } @Primary @Bean(name = "sqlSessionTemplate") public SqlSessionTemplate gfSqlSessionTemplate( @Qualifier("sqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory); return sqlSessionTemplate; } }
금 3월 12일 15:56:31 CST 2021--方法开始执行!!
2021-03-12 15:56:38.508 ERROR 24484 --- [nio-8111-exec-3] o.api.advice .ExceptionHandlerAdvice : 未知异常:
### 데이터베이스 쿼리 중 오류가 발생했습니다. 원인: com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 시간 초과 또는 클라이언트 요청으로 인해 명령문이 취소되었습니다
### [E:space-persionalgitoldmoon-frameoldmoon-app-billoutproductionresourcesmybatisUserMapper.xml]
## 파일에 오류가 있을 수 있습니다. # 해당 오류에는 defaultParameterMap이 포함될 수 있습니다
### 매개변수 설정 중 오류가 발생했습니다
### SQL: select * from V_BGD_PWGM_PB_21
### 원인: com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 시간 초과로 인해 명령문이 취소되었거나 클라이언트 요청
; 시간 초과 또는 고객 요청으로 인해 명세서가 취소되었습니다. 중첩 예외는 com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 시간 초과 또는 클라이언트 요청으로 인해 명령문이 취소되었습니다
org.springframework.dao.QueryTimeoutException:
### 데이터베이스 쿼리 중 오류가 발생했습니다. 원인: com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 시간 초과 또는 클라이언트 요청으로 인해 명령문이 취소되었습니다
### [E:space-persionalgitoldmoon-frameoldmoon-app-billoutproductionresourcesmybatisUserMapper.xml]
## 파일에 오류가 있을 수 있습니다. # 해당 오류에는 defaultParameterMap이 포함될 수 있습니다
### 매개변수 설정 중 오류가 발생했습니다
### SQL: select * from V_BGD_PWGM_PB_21
### 원인: com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 시간 초과로 인해 명령문이 취소되었거나 클라이언트 요청
; 시간 초과 또는 고객 요청으로 인해 명세서가 취소되었습니다. 중첩된 예외는 com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException입니다. 시간 초과 또는 클라이언트 요청으로 인해 명령문이 취소되었습니다
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76)
at org.springframework.jdbc .support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyB atisExceptionTranslator.java:73 )
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
com.sun.proxy.$Proxy63.selectList(알 수 없는 소스)
org.mybatis.spring.SqlSessionTemplate.selectList(S) qlSessionTemplate .java:230)
org.apache.ibatis.bound.MapperMethod.executeForMany(MapperMethod.java:139)
org.apache.ibatis.bound.MapperMethod.execute(MapperMethod.java:76)
org.apache에서 .ibatis.bound.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy69.testTimeOut(알 수 없는 소스)
at top.oldmoon.bill.service.impl.UserServiceImpl.testTimeOut(UserServiceImpl.java :32)
top.oldmoon.bill.contoller.UserController.testTimeOut(UserController.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(네이티브 메서드)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod에서. doInvoke(InvocableHandlerMethod.java:197)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( ServletInvocableHandlerMethod.java:106)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter . handlerInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java: 1061)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web에서. servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
javax.servlet.http.HttpServlet.service(HttpServlet .java:733)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
org.apache에서 .tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166)
com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
org.springframework.web.filter.OncePerRequestFilter에서 .doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
org.apache.catalina.core.ApplicationFilterChain에서 .internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
org.apache.catalina.core.ApplicationFilterChain에서 .doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
org.apache.catalina.valves.ErrorReportValve에서 .invoke(ErrorReportValve.java:92)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process에서 (AbstractProtocol.java:888)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java :49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util에서 .threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
원인: com.mysql.cj.jdbc.Exceptions.MySQLTimeoutException: 명령문 취소됨 시간 초과 또는 클라이언트 요청
at com.mysql.cj.jdbc.Exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:113)
at com.mysql.cj.jdbc.StatementImpl.checkCancelTimeout(StatementImpl.java:2191)
at com .mysql.cj.protocol.a.NativeProtocol.sendQueryPacket(NativeProtocol.java:1028)
at com.mysql.cj.NativeSession.execSQL(NativeSession.java:1075)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal (ClientPreparedStatement.java:930)
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3409)
at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 61 more
{ "resultCode": "2", "resultMsg": "未知异常,请联系管理员!", "token": null, "resultInfo": "\r\n### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request\r\n### The error may exist in file [E:\\space-persional\\git\\oldmoon-frame\\oldmoon-app-bill\\out\\production\\resources\\mybatis\\UserMapper.xml]\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: select * from V_BGD_PWGM_PB_21\r\n### Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request\n; Statement cancelled due to timeout or client request; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request" }
위 내용은 springboot 구성 mybatis의 SQL 실행 시간 초과를 해결하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!