Understanding the concurrent Request API times pointer exception when using Springboot+mybatis

Source: Internet
Author: User

Problem description

Using Springboot+mybatis as the backend framework, a null pointer exception is thrown in the background when the front-end requests two and more APIs at the same time.

The specific exception information is as follows:

org.apache.ibatis.exceptions.PersistenceException: # # # Error querying database. cause:java.lang.nullpointerexception### the error exist in MyBatis/mapper/cspmapper.xml### The error may involve cn.goldlone.mapper.cspmapper.selectscorebyno### the error occurred whileexecuting a query### Cause:java.lang.NullPointerException at Org.apache.ibatis.exceptions.ExceptionFactory.wrapException (Exceptionfactory.java:30) at Org.apache.ibatis.session.defaults.DefaultSqlSession.selectList (Defaultsqlsession.java:150) at Org.apache.ibatis.session.defaults.DefaultSqlSession.selectList (Defaultsqlsession.java:141) at Org.apache.ibatis.binding.MapperMethod.executeForMany (Mappermethod.java:137) at Org.apache.ibatis.binding.MapperMethod.execute (Mappermethod.java:75) at Org.apache.ibatis.binding.MapperProxy.invoke (Mapperproxy.java:59) at Com.sun.proxy. $Proxy 67.selectScoreByNo (Unknown Source) at Cn.goldlone.controller.CSPController.getScoreByC Ertno (Cspcontroller.java:163) 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.springframework.web.method.support.InvocableHandlerMethod.doInvoke (Invocablehandlermethod.java: 205) at Org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest ( Invocablehandlermethod.java:133) at Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( Servletinvocablehandlermethod.java:97) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod ( Requestmappinghandleradapter.java:827) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( Requestmappinghandleradapter.java:738) at Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( Abstracthandlermethodadapter.java:85) at Org.springframework.web.servlet.DispatcherServlet.doDispatch (Dispatcherservlet.java:967) at Org.springframework.web.servlet.DispatcherServlet.doService (Dispatcherservlet.java:901) at Org.springframework.web.servlet.FrameworkServlet.processRequest (Frameworkservlet.java:970) at Org.springframework.web.servlet.FrameworkServlet.doPost (Frameworkservlet.java:872) at Javax.servlet.http.HttpServlet.service (Httpservlet.java:661) at Org.springframework.web.servlet.FrameworkServlet.service (Frameworkservlet.java:846) at Javax.servlet.http.HttpServlet.service (Httpservlet.java:742) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:231) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.apache.tomcat.websocket.server.WsFilter.doFilter (Wsfilter.java:52) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.springframework.web.filter.CorsFilter.doFilterInternal (Corsfilter.java:96) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.springframework.web.filter.RequestContextFilter.doFilterInternal (Requestcontextfilter.java:99) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal (Httpputformcontentfilter.java: 108) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal (Hiddenhttpmethodfilter.java: 81) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at 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: 197) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (Onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (Applicationfilterchain.java:193) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (Applicationfilterchain.java:166) at Org.apache.catalina.core.StandardWrapperValve.invoke (Standardwrappervalve.java:199) at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java:96) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (Authenticatorbase.java:478) at Org.apache.catalina.core.StandardHostValve.invoke (Standardhostvalve.java:140) at Org.apache.catalina.valves.ErrorReportValve.invoke (Errorreportvalve.java:81) at Org.apache.catalina.core.StandardEngineValve.invoke (Standardenginevalve.java:87) at Org.apache.catalina.connector.CoyoteAdapter.service (Coyoteadapter.java:342) at Org.apache.coyote.http11.Http11Processor.service (Http11processor.java:803) at Org.apache.coyote.AbstractProcessorLight.process (Abstractprocessorlight.java:66) at Org.apache.coyote.abstractprotocol$connectionhandler.process (Abstractprotocol.java:868) at Org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun (Nioendpoint.java:1459) at Org.apache.tomcat.util.net.SocketProcessorBase.run (Socketprocessorbase.java:49) at Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1142) at Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:617) at Org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run (Taskthread.java:61) at Java.lang.Thread.run (Thread.java:745) caused by:java.lang.NullPointerException 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)    ... More

First, the implementation of the previous method, the direct Controller class to write business logic and open the MyBatis sqlsession manipulation database.

Solution Solutions

All business logic goes to the server tier, and each time the API is requested, it is re-new to the server class that corresponds to the business logic.

Then the problem is solved.

Understanding the concurrent Request API times pointer exception when using Springboot+mybatis

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.