Spring Data JPA中的分页问题

前端之家收集整理的这篇文章主要介绍了Spring Data JPA中的分页问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试Spring数据JPA,在启动我的项目时,我收到以下错误

@H_404_5@Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subjectRepository': factorybean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Paging query needs to have a Pageable parameter! at org.springframework.beans.factory.support.factorybeanRegistrySupport.doGetObjectFromfactorybean(factorybeanRegistrySupport.java:149) at org.springframework.beans.factory.support.factorybeanRegistrySupport.getObjectFromfactorybean(factorybeanRegistrySupport.java:102) at org.springframework.beans.factory.support.Abstractbeanfactory.getObjectForBeanInstance(Abstractbeanfactory.java:1441) at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:305) at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193) at org.springframework.beans.factory.support.DefaultListablebeanfactory.findAutowireCandidates(DefaultListablebeanfactory.java:848) at org.springframework.beans.factory.support.DefaultListablebeanfactory.doResolveDependency(DefaultListablebeanfactory.java:790) at org.springframework.beans.factory.support.DefaultListablebeanfactory.resolveDependency(DefaultListablebeanfactory.java:707) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.autowireConstructor(AbstractAutowireCapablebeanfactory.java:1035) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBeanInstance(AbstractAutowireCapablebeanfactory.java:939) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456) at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:291) at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:197) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1106) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456) at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:291) at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193) at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:672) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:403) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:664) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:239) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1212) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:610) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453) at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:234) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224) at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89) at org.eclipse.jetty.server.Server.doStart(Server.java:262) at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:67) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59) at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:333) at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:273) at org.mortbay.jetty.plugin.JettyRunMojo.execute(JettyRunMojo.java:548) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: java.lang.IllegalArgumentException: Paging query needs to have a Pageable parameter! at org.springframework.util.Assert.isTrue(Assert.java:65) at org.springframework.data.repository.query.QueryMethod.factorybeanSupport.getObject(RepositoryfactorybeanSupport.java:125) at org.springframework.data.repository.core.support.RepositoryfactorybeanSupport.getObject(RepositoryfactorybeanSupport.java:41) at org.springframework.beans.factory.support.factorybeanRegistrySupport.doGetObjectFromfactorybean(factorybeanRegistrySupport.java:142) at org.springframework.beans.factory.support.factorybeanRegistrySupport.getObjectFromfactorybean(factorybeanRegistrySupport.java:102) at org.springframework.beans.factory.support.Abstractbeanfactory.getObjectForBeanInstance(Abstractbeanfactory.java:1441) at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:305) at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193)

这是我的存储库:

@H_404_5@public interface SubjectRepository extends Repository

正如您所看到的,我已经评论了使用pageble的方法,并将父接口从jparepository更改为repository.But我仍然收到上述错误消息.有没有与persistence.xml相关的东西?
我的persistence.xml

@H_404_5@MysqL.jdbc.Driver"/> MysqL://localhost:3306/mydb?useUnicode=true&characterEncoding=UTF-8"/> MysqLDialect"/> sql" value="true"/> sql" value="true"/>

我的spring数据jpa配置:

@H_404_5@factorybean"> sql" value="true" />
最佳答案
您正在阅读错误消息错误

@H_404_5@Paging query needs to have a Pageable parameter!

你注释掉的方法是正确的,剩下的方法错误的!如果你想返回Page< PSubject>从查询方法来看,此方法必须具有Pageable参数.这是可以理解的:如果您询问特定结果页面,则必须首先定义您感兴趣的页面.

@H_404_5@Page

或者如果您对所有结果感兴趣,请使用List< PSubject>:

@H_404_5@Page
原文链接:https://www.f2er.com/spring/431788.html

猜你在找的Spring相关文章