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

Spring Boot报错:java.lang.IllegalArgumentException: Not a managed type

问题分析与解决方案

核心问题

Shoe实体的主键id类型为String,但ShoeRepositories继承JpaRepository时,第二个泛型参数(主键类型)错误指定为Integer,导致JPA无法正确识别实体主键规则,进而无法自动生成数据库表结构。

修复步骤

  1. 修正Repository泛型参数
    将ShoeRepositories的泛型主键类型改为String,与实体类的主键类型保持一致:
@Repository
public interface ShoeRepositories extends JpaRepository<Shoe, String> {

}
  1. 额外验证项
  • 确认MySQL中Sporty_Shoes数据库已提前创建
  • 检查数据库连接参数(用户名、密码、端口)是否正确
  • 若后续出现Repository无法被扫描的情况,可给@EnableJpaRepositories添加包路径配置:@EnableJpaRepositories(basePackages = "com.SportyShoe.repositories")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 06:06:19