ReflectionException: Illegal overloaded getter method with ambiguous type for property enabled in...

博主在Spring Boot整合修改Spring Security时,遇到Java和MyBatis映射冲突的bug,原因是类中同时出现isEnabled()和getEnabled()。给出两种解决办法,一是重命名isEnabled(),但因该方法是@Override,此方法不可行;二是删除getEnabled()方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我在springboot 整合修改spring security时,遇到一个java和mybatis映射冲突的bug。

nested exception is org.apache.ibatis.reflection.ReflectionException: Illegal overloaded getter method with ambiguous type for property enabled in class class com.teng.security.entity.User. This breaks the JavaBeans specification and can cause unpredictable results.

报错的原因是因为类中同时出现了 isEnabled() 和 getEnabled(),如下:

   @Override
    public boolean isEnabled() {
        return enabled;
    }
     public Boolean getEnabled() {
        return enabled;
    }

解决办法是
方法1.重命名isEnabled(),不要是is开头换成其他的,如:typeofEnabled()

(由于我上面isEnabled()是个@Override,显然方法1不行)
方法2:删除getEnabled()这个方法,通过上面可以发现他们返回的值是一样的,那就可以去掉一个。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值