Apabila sesetengah SQL disekat atas sebab yang tidak diketahui, untuk tidak menjejaskan perjalanan perkhidmatan latar belakang, kami ingin meningkatkan had masa pelaksanaan untuk SQL dan membuang pengecualian selepas tamat masa untuk memastikan bahawa urutan latar belakang akan tidak disekat kerana kesesakan SQL.
Sumber data tunggal OK, tetapi ia akan gagal apabila berbilang sumber data digunakan
Pengecualian tamat masa berjaya dibuang.
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; } }
Jumaat 12 Mac 15:56:31 CST 2021--方法开始执行!!
2021-03-12 15:56:38.508 RALAT 14484-1 --- ] o.api.advice.ExceptionHandlerAdvice : 未知异常:
### Ralat semasa membuat pertanyaan pangkalan data. Punca: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Pernyataan dibatalkan kerana tamat masa atau permintaan pelanggan
### Ralat mungkin wujud dalam fail [E:space-persionalgitoldmoon-frameoldmoon-app-billoutproductionresourcesmybatisUserMapper.xml]
### Ralat mungkin melibatkan defaultParameterMap
### Ralat berlaku semasa menetapkan parameter
### SQL: pilih * daripada V_BGD_PWGM_PB_21
### Punca: com.mysql.cj.jdbc. exceptions.MySQLTimeoutException: Penyata dibatalkan kerana tamat masa atau permintaan pelanggan
; Penyata dibatalkan kerana tamat masa atau permintaan pelanggan; Pengecualian bersarang ialah com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Pernyataan dibatalkan disebabkan oleh tamat masa atau permintaan klien
org.springframework.dao.QueryTimeoutException:
### Ralat semasa membuat pertanyaan pangkalan data. Punca: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Pernyataan dibatalkan kerana tamat masa atau permintaan pelanggan
### Ralat mungkin wujud dalam fail [E:space-persionalgitoldmoon-frameoldmoon-app-billoutproductionresourcesmybatisUserMapper.xml]
### Ralat mungkin melibatkan defaultParameterMap
### Ralat berlaku semasa menetapkan parameter
### SQL: pilih * daripada V_BGD_PWGM_PB_21
### Punca: com.mysql.cj.jdbc. exceptions.MySQLTimeoutException: Penyata dibatalkan kerana tamat masa atau permintaan pelanggan
; Penyata dibatalkan kerana tamat masa atau permintaan pelanggan; Pengecualian bersarang ialah com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Penyata dibatalkan kerana tamat masa atau permintaan klien
di org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator) java java .springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
di org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(QLE Fallback .mybatis.spring.MyBatisExceptionTranslator .translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
.Unknown Source .6 🎜> di org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(Method.Mapper.java:139) apa .binding.MapperMethod.execute(MapperMethod.java:76)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy69.testTimeOut( Sumber Tidak Diketahui)
di top.oldmoon.bill.service.impl.UserServiceImpl.testTimeOut(UserServiceImpl.java:32)
at top.oldmoon.bill.contoller.UserController.testTimeOut(Java:64Controller)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Kaedah Asli)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
memantulkan kaedah. DelegatingMethodAccessorImpl.java:43)
di java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197>) di org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerchodandle. 6)
pada org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
at org.springframework.web.servlet.mvc.method. .java: 808)
di org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.serverv.Dispatcher.web.serverv
di org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961)
di org.springframework.web.servlet.FrameworkServlet.processRequest(Frame Servlet.processRequest(Frame Servlet.java:961)
di org.springframework.web.servlet.FrameworkServlet.processRequest(Frame Servlet. springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
di javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
di org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
http . letSvletjava .service(HttpServlet.java:733)
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain. :166)
di org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain3)
di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
org.springframework .RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apachelterin.CatalinaFilter. .java:193)
di org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
di org.springframework.web.filter.FormContentFilter.doFilter3Internal(FormContentFilter.doFilter3Internal(.java:9ContentFilter) 🎜> di org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.🎜 di java.🎜 : apache .catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
di org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
org.springframework. .doFilter(OncePerRequestFilter.java:119)
di org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
di org.apache.catalina.core.ApplicationFilterChain. :166)
di org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
di org.apache.catalina.core.StandardContextValve.invoke(Standard.ContextValve.invoke(Standard.ContextValve.invoke(7)🎜ContextValve.invoke(7) di org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
di org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) apache at org> .valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
. at.coadapservice. (CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessor.Processor(Abightstract.Processor. 🎜> di org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(di java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
. .ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
di org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
. at java (Thread.java:748)
Disebabkan oleh: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Pernyataan dibatalkan kerana tamat masa atau permintaan pelanggan
di com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.transceptions (SQLExceptionsMapping.java:113)
at com.mysql.cj.jdbc.StatementImpl.checkCancelTimeout(StatementImpl.java:2191)
at com.mysql.cj.protocol.a.sqlNativeProtocol.cj. :1028)
di com.mysql.cj.NativeSession.execSQL(NativeSession.java:1075)
di com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPrepared:9 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" }
Atas ialah kandungan terperinci Bagaimana untuk menyelesaikan tamat masa pelaksanaan sql konfigurasi springboot mybatis. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!