Spring Boot uses pagehelper to report null pointer exceptions _mybatis

Source: Internet
Author: User

The use of Mybatis+pagehelper in the project is not a problem, should be required to configure a multiple data source, but when I configured, the new data source normal operation, the original query of the null pointer exception,
error is as follows:

2017-09-20 19:59:40.256 ERROR 17836---[nio-1010-exec-1]. P.s.c.m.e.globaldefaultexceptionhandler:----------------- ------Global Unified Exception Handling-----------------------2017-09-20 19:59:40.260 ERROR 17836---[nio-1010-exec-1]. P.s.c.m.e.globaldefaultexceptionhandler:org.mybatis.spring.mybatissystemexception:nested exception is  Org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause:java.lang.NullPointerException ### The error may exist in Com/paic/srvbot/change/dao/stepdao.java (best guess) ### The error may involve Com.paic.srvbot.change.dao.StepDao.selectByExample_COUNT ### the error occurred while handling ResU LTS ### Sql:select count (0) from Srv_change_step LIMIT to ### Cause:java.lang.NullPointerException at ORG.MYBATIS.SP Ring. Mybatisexceptiontranslator.translateexceptionifpossible (mybatisexceptiontranslator.java:77) at Org.mybatis.spring.sqlsessiontemplate$sqlsessioninterceptor.invoke (sqlsessiontemplate.java:446) at Com.sun.proxy . $Proxy 123.SelectList (Unknown Source) at Org.mybatis.spring.SqlSessionTemplate.selectList (sqlsessiontemplate.java:230) 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 161.selectByExample ( Unknown Source) at Com.paic.srvbot.change.service.impl.StepServiceImpl.findSteps (stepserviceimpl.java:64) at COM.P aic.srvbot.change.service.impl.stepserviceimpl$ $FastClassBySpringCGLIB $ $a 9da154a.invoke (<generated>) at Org.springframework.cglib.proxy.MethodProxy.invoke (methodproxy.java:204) at
    Org.springframework.aop.framework.cglibaopproxy$cglibmethodinvocation.invokejoinpoint (CglibAopProxy.java:721) At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:157) at Org.springframework.transaction.interceptor.TransactionIntercePtor$1.proceedwithinvocation (transactioninterceptor.java:99) at Org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction ( transactionaspectsupport.java:282) at Org.springframework.transaction.interceptor.TransactionInterceptor.invoke ( transactioninterceptor.java:96) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed ( reflectivemethodinvocation.java:179) at org.springframework.aop.framework.cglibaopproxy$ Dynamicadvisedinterceptor.intercept (cglibaopproxy.java:656) at com.paic.srvbot.change.service.impl.stepserviceimpl$ $EnhancerBySpringCGLIB $ $f 955a0c0.findsteps (<generated >) at Com.paic.srvbot.change.controller.StepController.find (stepcontroller.java:46) at Sun.reflect.NativeMethod Accessorimpl.invoke0 (Native method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Nativemethodaccessorimpl.java At Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:43) at Java.Lang.reflect.Method.invoke (method.java:497) 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:116) 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:963) at Org.springframework.web.servlet.DispatcherServlet.doService(dispatcherservlet.java:897) at Org.springframework.web.servlet.FrameworkServlet.processRequest ( frameworkservlet.java:970) at Org.springframework.web.servlet.FrameworkServlet.doGet (frameworkservlet.java:861) A T Javax.servlet.http.HttpServlet.service (httpservlet.java:622) at Org.springframework.web.servlet.FrameworkServlet.service (frameworkservlet.java:846) at Javax.servlet.http.HttpServlet.service (httpservlet.java:729) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:230) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) at Org.apache.tomcat.websocket.server.WsFilter.doFilter (wsfilter.java:52) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) at Org.springframework.security.web.FilterChainProxy.doFilterInternal (Filterchainproxy.java:208) at Org.springframework.security.web.FilterChainProxy.doFilter (Filterchainproxy.java : 177) at Org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (delegatingfilterproxy.java:346) at or G.springframework.web.filter.delegatingfilterproxy.dofilter (delegatingfilterproxy.java:262) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) 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:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) at Org.springframework.web.filter.httpputformcontentfilter.dOfilterinternal (httpputformcontentfilter.java:105) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) 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:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) 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:192) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:165) at Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:198) at Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:96) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:474) at Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:140) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:79) at Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:87) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:349) at Org.apache.coyote.http11.Http11Processor.service (http11processor.java:783) at Org.apache.coyote.AbstractProcessorLight.process (abstractprocessorlight.java:66) at Org.apache.coyote.AbstractProtoCol$connectionhandler.process (abstractprotocol.java:798) at org.apache.tomcat.util.net.nioendpoint$ Socketprocessor.dorun (nioendpoint.java:1434) at Org.apache.tomcat.util.net.SocketProcessorBase.run ( socketprocessorbase.java:49) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1142) A T 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:org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause:java.lang.NullPointerException ### The error may exist in Com/paic/srvbot/change/dao/stepdao.java (best guess) ### The error may involve Com.paic.srvbot.change.dao.StepDao.selectByExample_COUNT ### the error occurred while handling ResU LTS ### Sql:select count (0) from Srv_change_step LIMIT to ### 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 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:497) at Org.mybatis.spring.Sq Lsessiontemplate$sqlsessioninterceptor.invoke (sqlsessiontemplate.java:433) ... caused by:java.lang.NullPointerException at Com.github.pagehelper.dialect.AbstractHelperDialect.afterCount ( abstracthelperdialect.java:71) at Com.github.pagehelper.PageHelper.afterCount (pagehelper.java:73) at COM.GITHUB.PA Gehelper. Pageinterceptor.intercept (pageinterceptor.java:115) at Org.apAche.ibatis.plugin.Plugin.invoke (plugin.java:61) at Com.sun.proxy. $Proxy 210.query (Unknown Source) at Org.apache.ib Atis.session.defaults.DefaultSqlSession.selectList (defaultsqlsession.java:148) ...
 More

The reason is that dependency is not right
The original

Application.properties

Pagehelper.helperdialect=postgresql

Key content

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId> pagehelper-spring-boot-starter</artifactid>
            <version>1.1.0</version>
        </dependency >

After the change

       <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactid>pagehelper </artifactId>
            <version>5.0.0</version>
       </dependency>

The guess is that the original Pagehelper configuration is written in the configuration file, Springboot automatically reads the configuration and is now written in the overridden Sqlsessionfactory class.
The reason for rewriting sqlsessionfactory is that two data sources one is PG and one is Oracle, they use different pagehelper.helperdialect, so they have to be configured separately

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.