org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name(已解决)

报错内容的一部分

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<UserEntity> {

        (3)服务实现类(注意不是服务类,是服务类的实现)上方的@Service:

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements 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的问题

完结撒花!❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀

  • 11
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值