You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Spring Boot 4.20.1后STS问题面板出现ID类型错误,如何忽略?

解决STS中Spring Data ID类型不匹配的错误提示

首先说下问题本质:你的TestInfo实体id是long(对应包装类Long),但Repository泛型里写的是Integer,STS的Spring Data插件会做严格的类型校验,所以弹出这个提示。虽然应用能正常运行,但这属于类型不匹配的不规范写法,优先建议直接修正根源:

  • 把Repository的泛型改成Long,代码调整为:
    public interface TestInfoRepository extends PagingAndSortingRepository<TestInfo, Long>{}
    

如果确实需要忽略这个错误提示,有两种可行方式:

单个文件忽略

在STS里找到报错的Repository接口,右键问题面板中的错误→选择「Quick Fix」,然后选「Suppress warning for this element」,IDE会自动给接口加上对应的@SuppressWarnings注解,示例:

@SuppressWarnings("spring-data-repository-type-mismatch")
public interface TestInfoRepository extends PagingAndSortingRepository<TestInfo, Integer>{}

全局忽略所有此类错误

打开STS的偏好设置:

  • Windows系统:顶部菜单「Window」→「Preferences」
  • Mac系统:顶部菜单「STS」→「Settings」
    依次展开「Spring」→「Data」→「Repository Checks」,找到「Domain ID type matches repository ID type」这条规则,取消勾选后点击「Apply」再「OK」,所有此类错误提示就会消失。

内容的提问来源于stack exchange,提问作者anonymouss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 23:59:55