关于Springboot调错篇
遇到两次了,第一次很快解决了,花了15分钟;第二次花了半个多小时!
遇到两次了,第一次很快解决了,花了15分钟;第二次花了半个多小时!
所以,具体描述一下,以备记录,后期不要再被卡半个小时了。首先看看效果。
控制台不停在告警,随便粘贴几条看看:
2017-06-06 17:46:10.242 WARN 6524 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'monthReportMapper' defined in file [F:\springboot-mybatis-master\springboot-mybatis-master\target\classes\com\droi\monthReport\mapper\MonthReportMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO)
2017-06-06 17:46:10.254 WARN 6524 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'droiActiveMapper' defined in file [F:\springboot-mybatis-master\springboot-mybatis-master\target\classes\com\droi\droiActive\mapper\DroiActiveMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO)
2017-06-06 17:46:10.266 WARN 6524 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on FactoryBean type check: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'droiActiveMapper' defined in file [F:\springboot-mybatis-master\springboot-mybatis-master\target\classes\com\droi\droiActive\mapper\DroiActiveMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO)
提示无法找到这个bean,那么,仔细看一下console报错日志,提示:
粘贴出来看一下:
lSessionFactory': : Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO); nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in com.droi.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactoryBean' threw exception; nested exception is java.lang.NoClassDefFoundError: com/droi/droiActive/model/droiActiveVO (wrong name: com/droi/droiActive/model/DroiActiveVO)
原来原因是:无法实例化
由于找不到定义的实体类,那么我们跟着这个报错去看看一看mapper接口:
可以看到mapper的映射方法名,那么去找mybatis的sql-map配置文件去看看,粘贴出来:
发现了!
开心的启动了,我曹,怎么还是这样啊,还是不停的打日志,好难受、不舒服。
赶紧接着找原因,然后打了自己一巴掌,傻兮兮的,人家都告诉你了,实体类找不到,没有办法实例化你这个实体类,结果,哎,默默的看向了引用实体类,附上截图:
哎,又是大小写,很难受啊。改好之后,接着启动,fuck,报错继续:
日志,分析一下哈:
2017-06-06 18:01:32.176 WARN 5208 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'droiActiveController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.droi.droiActive.service.DroiActiveService com.droi.droiActive.controller.DroiActiveController.droiActiveService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.droi.droiActive.service.DroiActiveService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
在context初始化的时候失败,建议:取消刷新尝试。而且明确告诉了我们是哪一个controller出的问题, droiActiveController,原因是: Injection of autowired dependencies failed
并且,
No qualifying bean of type [com.droi.droiActive.service.DroiActiveService] found for dependency
很显然,注入注解失败,那就去controller看看吧。
很显然我声明了这个呀
怎么回事,换了一种方式,继续,
这两种方式都是告诉spring去寻找bean的注入,那么,启动依然报错,那么问题只可能出现在这里了,service层。
请看:
这不:
service层需要注解service:
都是坑啊,我在也不自己敲了,能ctrl c + Ctrl v 就别自己闲着自己敲。(今天给同事培训,写demo没办法啊,总不能一句不敲吧)
给看下成功的日志吧:
SpringBoot Start Success!Dazhuang is so [email protected]^_^@~
看到没!很happy!
浏览器验证一下是否开发完毕,查询所得数据,希望不要在报错了,结果:
么有数据,很难受,我的天,没办法,接着找错:
去navicat校验sql发现没问题,是由数据的,
那应该就是变量的map没传到mabatis的映射吧,去瞅瞅:
我靠,连断点都不进了,很尴尬。
然后我气愤的重启了,就又有数据了,原来是之前改动了,没有重启,很气愤:
完美!
渐渐的,自己搭的框架越来越成熟了。
向着架构师的道路继续前进!