今天运行程序时报了

SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@69d4fb43] was not registered for synchronization because synchronization is not active

[11:03:17]-Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@69d4fb43]

由于异常是集中处理的,所以报了这样的错误,查了半天,网上结果都是说配置文件出错的,可是我的项目配置文件肯定是没错的,因为项目都开发了好长时间了,只是我今天写了个方法才报的这个错误,所以排除配置文件出错,可是我写的方法应该没问题的,以前也这样写的呀。

      网上查半天没找到原因,没办法,只能看看自己的程序了,把自己写的方法异常直接打印出来,先不集中处理,然后异常出来了:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘departid‘ in ‘class java.lang.String‘

 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)

 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)

 at com.sun.proxy.$Proxy15.selectOne(Unknown Source)

 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)

 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)

 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)

 at com.sun.proxy.$Proxy125.selectCount(Unknown Source)

 at com.sinog2c.service.impl.yzgl.TbyzScoreServiceImpl.selectCount(TbyzScoreServiceImpl.java:66)

 at com.sinog2c.mvc.controller.yzgl.criminalexam.JifenController.getLastMonthScoreList(JifenController.java:76)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

 at java.lang.reflect.Method.invoke(Method.java:597)

 at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)

 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)

 at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)

 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)

 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)

 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)

 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)

 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)

 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)

 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

 at java.lang.Thread.run(Thread.java:662)

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘departid‘ in ‘class java.lang.String‘

 at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380)

 at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170)

 at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152)

 at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)

 at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)

 at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:97)

 at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:116)

 at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)

 at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:49)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:56)

 at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)

 at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)

 at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)

 at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:48)

 at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)

 at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:33)

 at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)

 at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:40)

 at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:278)

 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:75)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)

 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

 at java.lang.reflect.Method.invoke(Method.java:597)

 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)

 ... 40 more

根据这个异常再查程序,发现问题出现在departid这个参数,再查源程序,发现原来我写的那个方法的sql在mapper.xml文件里引用了对参数departid进行判断是否为null或空,所以才报 There is no getter for property named ‘departid‘ in ‘class java.lang.String‘异常。

解决方法:一、在方法传参时,加param参数标识,如:countNum(@Param("departid")String departid);

                  二、在方法传参时,把参数换成map或对象。

希望通过此文能解决这类问题,谢谢大家对本站的支持!

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com