Illegal overloaded getter method with ambiguous type for property enabled in class class com.zhu.erp.entities.UserLogin. This breaks the JavaBeans specification and can cause unpredictable results.

Published on with 0 views and 0 comments

首先能得知com.zhu.erp.entities.UserLogin字段enabled非法重载getter

原因为:UserLogin实现了UserDetail接口,但是UserLogin有一个字段为String enable,并且使用了@Data

public interface UserDetails extends Serializable {
    Collection<? extends GrantedAuthority> getAuthorities();

    String getPassword();

    String getUsername();

    boolean isAccountNonExpired();

    boolean isAccountNonLocked();

    boolean isCredentialsNonExpired();

    boolean isEnabled();
}

解决方法: 使用特殊 AccessLevel.NONE访问级别手动禁用enable的getter / setter生成,手动重写setEnable方法,

如果不写会与isEnabled字段进行冲突,因为isEnabled的类型是boolean所以要求的是传入boolean的enable。

DataIntegrityViolationException:Error attempting to get column 'ENABLED' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'Y'

    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    @TableField("ENABLED")
    private String enabled;

    public void setEnabled(String enabled) {
        this.enabled = enabled;
        this.isEnabled = StringUtils.isEmpty(this.enabled)?false:this.enabled.equalsIgnoreCase("Y")?true:false;
    }
    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }

标题:Illegal overloaded getter method with ambiguous type for property enabled in class class com.zhu.erp.entities.UserLogin. This breaks the JavaBeans specification and can cause unpredictable results.
作者:Zcoin
地址:https://zzzerp.cn/articles/2020/06/17/1592324344335.html