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测试