首页 文章

编写Spring启动程序时出错

提问于
浏览
0

我正在写一个Rest服务来将数据保存到mysql中 . 该程序使用Spring引导,Hibernate和Gradle作为依赖项 .

我的客户给了我程序结构(基本上是必需的java文件,gradle文件等) . 我编写了业务逻辑来将数据存储到MySQL . 但它给我编译时错误如下:

  • 错误org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名称为'requestMappingHandlerAdapter'的bean时出错[org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration $ EnableWebMvcConfiguration.class]:通过工厂方法进行Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:工厂方法'requestMappingHandlerAdapter'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'mvcConversionService'的bean时出错[org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration $ EnableWebMvcConfiguration.class]:通过工厂方法进行Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.format.support.FormattingConversionService]:工厂方法'mvcConversionService'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)~ [spring-beans-4.3.9 .RELEASE.jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9 . 发布org.springframework.beans上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)~ [spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] . factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory) .java:483)〜[spring-be ans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.9.RELEASE . jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.beans.factory.support org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons中的.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)~ [spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE](DefaultListableBeanFactory.java: 761)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)~ [spring-cont ext-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)〜[spring-context-4.3.9.RELEASE.jar:4.3 .9.RELEASE] org.springframework上的org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)~ [spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE] .boot.SpringApplication.refresh(SpringApplication.java:762)[spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE] org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)[ spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)[spring-boot-1.4.7.RELEASE.jar:1.4 . 7.RELEASE] org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)[spring-boot-1.4.7.RELEASE.jar:1.4.7.RELEASE] org.springframework.boot.SpringApplication.run (SpringApplication.java:1176)[spring-boot-1.4.7.RELEASE.jar:1.4.7.RELE ASE] at ae.dubaitrade.mawani.SsrApplication.main(SsrApplication.java:13)[bin /:na]引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.web.servlet.mvc . method.annotation.RequestMappingHandlerAdapter]:工厂方法'requestMappingHandlerAdapter'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'mvcConversionService'的bean时出错[org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration $ EnableWebMvcConfiguration.class]:通过工厂方法进行Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.format.support.FormattingConversionService]:工厂方法'mvcConversionService'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)〜[spring-beans-4.3.9 .RELEASE.jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9 . RELEASE] ...省略了18个常见帧引起:org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名称为'mvcConversionService'的bean时出错[org / springframework / boot / autoconfigure / web / WebMvcAutoConfiguration $ EnableWebMvcConfiguration . class]:通过工厂方法实例化Bean失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.format.support.FormattingConversionService]:工厂方法'mvcConversionService'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)~ [spring-beans-4.3.9 .RELEASE.jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9 . 发布org.springframework.beans上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)~ [spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] . factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory) .java:483)〜[spring-be ans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.9.RELEASE . jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] at at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.beans.factory.support .AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.obtainBeanInstanceFromFactory(ConfigurationClassEnhancer.java: 389)〜[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnh ancer.java:361)~ [spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ EnableWebMvcConfiguration $$ EnhancerBySpringCGLIB $$ 50193bf1.mvcConversionService() 〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE]在org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.getConfigurableWebBindingInitializer(WebMvcConfigurationSupport.java:566)〜[spring-webmvc -4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ EnableWebMvcConfiguration.getConfigurableWebBindingInitializer(WebMvcAutoConfiguration.java:411)〜[spring-boot-autoconfigure-1.4.7 . RELEASE.jar:1.4.7.RELEASE] at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter(WebMvcConfigurationSupport.java:526)~ [spring-webmvc-4.3.9.RELEASE.jar:4.3.9 .RELEASE] org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ EnableWebMvcConfiguration .requestMappingHandlerAdapter(WebMvcAutoConfiguration.java:373)〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] atorg.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ EnhanceWebMvcConfiguration $$ EnhancerBySpringCGLIB $$ 50193bf1.CGLIB $ requestMappingHandlerAdapter $ 2()〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] at org .springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ EnableWebMvcConfiguration $$ EnhancerBySpringCGLIB $$ 50193bf1 $$ FastClassBySpringCGLIB $$ 16dec672.invoke()〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)〜[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.context.annotation.ConfigurationClassEnhancer $ org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration上的BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)〜[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] $ EnableWebMvcConfiguration $$ EnhancerBySpringCGLIB $$ 50193bf1 .requestMappingHandlerAdapter()〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] at s at.reflect.NativeMethodAccessorImpl.invoke0(原生方法)〜[na:1.8.0_45] at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source )〜[na:1.8.0_45] at java.lang.reflect.Method.invoke(未知来源)〜[na:1.8.0_45] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java: 162)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] ... 19个常见帧省略引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.format . support.FormattingConversionService]:工厂方法'mvcConversionService'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)〜[spring-beans-4.3.9 .RELEASE.jar:4.3.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9 . RELEASE] ...省略了44个常见帧引起:org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)~ [spring-beans-4.3.9 .RELEASE.jar:4.3.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)~ [spring-beans-4.3.9.RELEASE.jar:4.3.9 . 发布org.springframework.beans上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] . orgs.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton上的factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]在org.springfr的DefaultSingletonBeanRegistry.java:230)~ [spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] orme.springframework.beans.factory.support.AbstractBeanFactory上的amework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE] .getBean(AbstractBeanFactory.java:202)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1084)〜[ spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:95)〜[spring-data-commons-1.12.11 .rELEASE.jar:na] at org.springframework上的org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:88)〜[spring-data-commons-1.12.11.RELEASE.jar:na] .data.repository.support.Repositories . (Repositories.java:81)〜[spring-data-commons-1.12.11.RELEASE.jar:na] at org.springframework.data.repository.support.DomainClassConverter.setApplicationContext(DomainClassCon) verter.java:98)〜[spring-data-commons-1.12.11.RELEASE.jar:na] at org.springframework.data.web.config.SpringDataWebConfiguration.addFormatters(SpringDataWebConfiguration.java:87)〜[spring-data -commons-1.12.11.RELEASE.jar:na] at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.addFormatters(WebMvcConfigurerComposite.java:80)〜[spring-webmvc-4.3.9.RELEASE.jar: 4.3.9.RELEASE] atorg.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.addFormatters(DelegatingWebMvcConfiguration.java:77)〜[spring-webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.web.servlet .config.annotation.WebMvcConfigurationSupport.mvcConversionService(WebMvcConfigurationSupport.java:594)〜[ spring webmvc-4.3.9.RELEASE.jar:4.3.9.RELEASE]在org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ $ EnableWebMvcConfiguration $ $$ EnhancerBySpringCGLIB $ 50193bf1.CGLIB $ mvcConversionService 41()〜[ spring 引导自动配置-1.4.7.RELEASE.jar:1.4.7.RELEASE]在org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ $$ EnableWebMvcConfiguration在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy)中的EnhancerBySpringCGLIB $$ 50193bf1 $$ FastClassBySpringCGLIB $$ 16dec672.invoke()〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] .java:228)〜[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE] org.springframework.context.annotation.Config urationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)〜[ spring 上下文4.3.9.RELEASE.jar:4.3.9.RELEASE]在org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration $ $$ EnableWebMvcConfiguration $ EnhancerBySpringCGLIB在sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)〜[na:1.8.0_45]太阳报$ 50193bf1.mvcConversionService()〜[spring-boot-autoconfigure-1.4.7.RELEASE.jar:1.4.7.RELEASE] .reflect.NativeMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_45] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)〜[na:1.8.0_45] at java.lang.reflect.Method.invoke(Unknown来源)〜[na:1.8.0_45] org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)〜[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE ] ...省略了45个常见框架引起:java.lang.IllegalArgumentException:不是托管类型:org.hibernate.jpa.internal.metamodel.MetamodelImpl.m中的类java.lang.Long org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation上的anagedType(MetamodelImpl.java:210)~ [hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] . (JpaMetamodelEntityInformation.java:70) 〜[spring-data-jpa-1.10.11.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:68)〜[spring-data-jpa-1.10 .11.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:153)〜[spring-data-jpa-1.10.11.RELEASE.jar:na]在org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:100)〜[spring-data-jpa-1.10.11.RELEASE.jar:na] org.springframework.data.jpa . repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:82)〜[spring-data-jpa-1.10.11.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySu pport.getRepository(RepositoryFactorySupport.java:199)〜[ spring 数据公地1.12.11.RELEASE.jar:NA]在org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:280 )〜[spring-data-commons-1.12.11.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:266)〜[spring-data-commons- 1.12.11.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)〜[spring-data-jpa-1.10.11.RELEASE.jar:na ]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)〜[ spring beans -4.3.9.RELEASE.jar:4.3.9.RELEASE]在org.springframework.beans.factory .support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)~ [spring-beans-4.3.9.RELEASE.j ar:4.3.9.RELEASE] ...省略了70个常用帧

  • Gradle文件

buildscript {\ text 存储库{mavenCentral()}依赖关系{classpath(“org.springframework.boot:spring-boot-gradle-plugin:$ ”)}}

apply plugin:'java'apply plugin:'eclipse'apply plugin:'org.springframework.boot'

group =''version ='0.0.1-SNAPSHOT'sourceCompatibility = 1.8

存储库{mavenCentral()}

\ text

依赖{compile('org.springframework.cloud:spring-cloud-starter-feign')compile('org.springframework.boot:spring-boot-starter-data-jpa')compile('org.springframework.boot:spring -boot-starter-jdbc')compile('org.springframework.boot:spring-boot-starter-thymeleaf')编译组:'mysql',名称:'mysql-connector-java',版本:'5.1.6' compile('org.springframework.boot:spring-boot-starter-web')testCompile('org.springframework.boot:spring-boot-starter-test')compile('org.springframework:spring-webmvc')compile('org.springframework:spring-core')

}

dependencyManagement {imports {mavenBom“org.springframework.cloud:spring-cloud-dependencies:$”}}

2 回答

  • 0

    很难说清楚这里发生了什么,但我建议重要的错误信息如下:

    org.springframework.beans.factory.BeanCreationException:创建名为'SSRRepository'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:类java.lang.Long at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)

    您的一个Spring bean依赖于 SSRRepository 类,其构造函数需要一个类型为 Long 的参数 . 但是您的应用程序不包含 Long 类型的bean . 因此,Spring无法实例化该类以实现依赖性 .

    检查 SSRRepository 类的构造函数,看看它期望的值 . 如果这样做有意义,请创建一个返回正确 Long 值的bean方法 .

  • 1

    但它给出了编译时错误,如下所示:错误org.springframework.beans.factory.BeanCreationException:创建名为'requestMappingHandlerAdapter'的bean时出错

    这是运行时错误,而不是编译时错误 .

    您的一个Spring bean依赖于SSRRepository类,其构造函数需要Long类型的参数 . 但是您的应用程序不包含Long类型的bean .

    您不必创建通用数据类型的Spring bean . JpaRepository抛出错误,因此我假设您在存储库中交换了类型定义 . JpaRepository需要类型参数 <Entity, ID> . 如果您的实体类"MyEntity"具有类型为Long的ID,则可以定义存储库 ... implements JpaRepository<MyEntity, Long>... .

    但是如果交换类型定义( <Long, MyEntity> 而不是 <MyEntity, Long> ),Long将成为实体,MyEntity将成为ID类,JpaRepository将抛出此错误 .

相关问题