maven管理的 spring+springmvc+mybatis【ssm】整合-遇到的bug及解决方法

bug1

描述:

部署tomcat后,启动就报错

报错信息:

16-May-2023 20:49:59.299 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
16-May-2023 20:49:59.432 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcherServlet'
16-May-2023 20:49:59.834 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Servlet[dispatcherServlet]的Servlet.init()引发异常
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'empController': Unsatisfied dependency expressed through field 'empService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.mybatis.spring.SqlSessionFactoryBean] for bean with name 'sqlSessionFactory' defined in file [D:\software\apache-tomcat-8.5.88\webapps\my_sencond_ssm_war\WEB-INF\classes\spring-mvc.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: org/mybatis/spring/SqlSessionFactoryBean has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (无法载入的类 [org.mybatis.spring.SqlSessionFactoryBean])
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

解决思路:

版本问题,pom.xml排除查找后发现是mybatis-spring这个依赖的版本过高

修改为1.3.0版本

 

 注意:一定要去编译文件里看是否修改成功,有可能出现两个版本的jar包,可能会导致启动tomcat不稳定,同样报错。最好是删掉target文件夹并重新编译。

结果:

启动成功

bug2

描述:

需求:查询员工表所有信息

问题:无法连接数据库

 

解决思路:

一看就是数据库连接有问题,但经过我粗心的排查,未能发现问题

尝试不用jdbc.properties,写死参数,发现竟然成功了。

对比了半天,被自己蠢哭了,原来是jdbc.properties里参数不应该加" "

 错误写法:

正确写法:

 结果:

postman测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值