报错内容的一部分
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': Error creating bean with name 'userMapper' defined in file [E:\vdtsp01\RegisterandLogin\Server\target\classes\com\gsy\server\mapper\UserMapper.class]: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
尝试过的办法
补全注释
(1)启动类上面的@MapperScan:
@MapperScan(basePackages = "com.gsy.server.mapper", sqlSessionFactoryRef = "sqlSessionFactory") public class UserServerApplication {
(2)mapper类上面的@Mapper:
@Mapper public interface UserMapper extends BaseMapper{
(3)服务实现类(注意不是服务类,是服务类的实现)上方的@Service:
@Service public class UserServiceImpl extends ServiceImplimplements UserService {
(4)一些需要注入的类上面的@AutoWired:
@Autowired private UserMapper userMapper;
补全yml文件
server: port: 3231 spring: datasource: url: jdbc:mysql://localhost:3306/userdemo?characterEncoding=UTF8&autoReconnect=true&serverTimezone=Asia/Shanghai&allowMultiQueries=true username: root password: ***** driver-class-name: com.mysql.cj.jdbc.Driver
但是以上方式都没用,最后降低jdk和java的版本,报错消失了。
最后解决方式
最后抱着尝试的心理改变了jdk、java的版本,从17变为8。
对于版本高一点的IEDA,选不了8,解决方法参考:
解决IntelliJ IDEA 2023版本创建Spring项目时Java只能选择17或21的问题
完结撒花!❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀
还没有评论,来说两句吧...