1、如果在SpringBoot的启动入口类上面加入注解
@MapperScan(basePackages = "com.leecx.mapper") 使用的是 org.mybatis.spring.annotation.MapperScan;
那么在使用通用Mapper插件的时候 会报错 信息如下:
1 2018-04-12 17:52:54.195 INFO 6972 --- [nio-8080-exec-4] c.l.controller.MyBatisCRUDController : 保存用户, 当前时间:Thu Apr 12 17:52:54 CST 2018, 操作人:Jack 2 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider 3 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) 4 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) 5 at com.sun.proxy.$Proxy72.insert(Unknown Source) 6 at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278) 7 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58) 8 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) 9 at com.sun.proxy.$Proxy73.insert(Unknown Source) 10 at com.leecx.service.impl.UserServiceImpl.saveUser(UserServiceImpl.java:23) 11 at com.leecx.controller.MyBatisCRUDController.saveUser(MyBatisCRUDController.java:44) 12 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 13 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 14 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 15 at java.lang.reflect.Method.invoke(Method.java:498) 16 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) 17 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) 18 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) 19 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) 20 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) 21 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 22 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) 23 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) 24 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) 25 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) 26 at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 27 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) 28 at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 29 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 30 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 31 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 32 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 33 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 34 at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) 35 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 36 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 37 at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) 38 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 39 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 40 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 41 at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) 42 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 43 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 44 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 45 at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) 46 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 47 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 48 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 49 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) 50 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 51 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 52 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 53 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) 54 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 55 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) 56 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 57 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 58 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 59 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 60 at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) 61 at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 62 at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) 63 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) 64 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 65 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 66 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 67 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 68 at java.lang.Thread.run(Thread.java:748) 69 Caused by: org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider 70 at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java:134) 71 at org.apache.ibatis.builder.annotation.ProviderSqlSource.getBoundSql(ProviderSqlSource.java:102) 72 at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292) 73 at org.apache.ibatis.executor.statement.BaseStatementHandler.(BaseStatementHandler.java:64) 74 at org.apache.ibatis.executor.statement.PreparedStatementHandler. (PreparedStatementHandler.java:40) 75 at org.apache.ibatis.executor.statement.RoutingStatementHandler. (RoutingStatementHandler.java:46) 76 at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:558) 77 at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48) 78 at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) 79 at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) 80 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 81 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 82 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 83 at java.lang.reflect.Method.invoke(Method.java:498) 84 at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) 85 at com.sun.proxy.$Proxy90.update(Unknown Source) 86 at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) 87 at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) 88 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 89 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 90 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 91 at java.lang.reflect.Method.invoke(Method.java:498) 92 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 93 ... 64 more 94 Caused by: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider 95 at java.lang.Class.newInstance(Class.java:427) 96 at org.apache.ibatis.builder.annotation.ProviderSqlSource.invokeProviderMethod(ProviderSqlSource.java:165) 97 at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java:116) 98 ... 86 more 99 Caused by: java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseInsertProvider. ()100 at java.lang.Class.getConstructor0(Class.java:3082)101 at java.lang.Class.newInstance(Class.java:412)102 ... 88 more103 2018-04-12 17:52:54.201 WARN 6972 --- [nio-8080-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL). Cause: java.lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider
对于 这种报错 解决方法如下:
在SpringBoot的启动入口类上面加入注解 由原来的
@MapperScan(basePackages = "com.leecx.mapper") 使用的是 org.mybatis.spring.annotation.MapperScan;
改为
@tk.mybatis.spring.annotation.MapperScan(basePackages = "com.leecx.mapper") 使用的是 tk.mybatis.spring.annotation.MapperScan
可以避免如上错误信息