2019-05-28
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring-context.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
...
Caused by: java.lang.NullPointerException
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:446)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758)
... 64 more
mybatis-spring集成过程出现错误,报空指针异常java.lang.NullPointerException
,查看AbstractAutowireCapableBeanFactory.java:1762
可以发现RootBeanDefinition
为null导致,所以推测是RootBeanDefinition注入失败。
因为spring+springMVC正常,所以spring注入功能是正常的,并且项目中使用mybatis的插件mybatis-generator正常,所以mybatis正常,所以最后推测是mybatis-spring的jar包有问题,查看之前的项目,发现之前用的是1.3.2,目前用的是2.0.0,查看相关依赖支持
版本 | javax.servlet-api |
---|---|
1.3.2 | 3.0.1 |
2.0.0 | 4.0.1 |
我用的是本地tomcat,tomcat自带的版本应该不足4.0.1导致我使用2.0.0失败,将mybatis-spring版本用1.3.2成功
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
所以啊,使用maven库时不要盲目用新的,用使用较多的比较保险~~~