问题描述
1、这个是jpa配置,其中配置了repository-impl-postfix="Impl"这一项。<jpa:repositoriesbase-package="com.nk"repository-impl-postfix="Impl"entity-manager-factory-ref="entityManagerFactory"transaction-manager-ref="transactionManager"></jpa:repositories>
2、接口publicinterfacePermissionDaoextendsPagingAndSortingRepository<Permission,Integer>{/*方法的实现由PermissionDaoImpl完成*/List<Permission>findByEmployeeId(IntegeremployeeId);}
3、实现,由于sql比较复杂,由mybatis实现。publicclassPermissionDAOImplextendsBaseDaoImpl<Permission>{publicPermissionDAOImpl(){super(Permission.class);}/*实现的是接口中的方法*/publicList<Permission>findByEmployeeId(IntegeremployeeId){Map<String,Object>params=newHashMap<String,Object>();params.put("employeeId",employeeId);returnsuper.sqlSession.selectList(super.entityMapper+"findByEmployeeId",employeeId);}}
结果:项目启动时报错:Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)atorg.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)...43moreCausedby:java.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:164)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:71)atorg.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:303)atorg.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:157)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)...56moreCausedby:java.lang.IllegalArgumentException:Nopropertyemployeefoundfortypeclasscom.nk.emis.basedata.entity.Permissionatorg.springframework.data.repository.query.parser.Property.<init>(Property.java:76)atorg.springframework.data.repository.query.parser.Property.<init>(Property.java:97)atorg.springframework.data.repository.query.parser.Property.create(Property.java:312)atorg.springframework.data.repository.query.parser.Property.create(Property.java:326)atorg.springframework.data.repository.query.parser.Property.create(Property.java:292)atorg.springframework.data.repository.query.parser.Property.from(Property.java:251)atorg.springframework.data.repository.query.parser.Property.from(Property.java:232)atorg.springframework.data.repository.query.parser.Part.<init>(Part.java:48)atorg.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:242)atorg.springframework.data.repository.query.parser.PartTree.buildTree(PartTree.java:101)atorg.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:77)atorg.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:56)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)...63more
说是我的Permission实体中没有那个属性,我的实体中确实没有,可是我由impl实现的。现在我想用impl去实现这个方法,该怎么处理?
解决方案
解决方案二:
完整异常严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionServiceImpl':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4630)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)atorg.apache.catalina.core.StandardHost.start(StandardHost.java:785)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)atorg.apache.catalina.startup.Embedded.start(Embedded.java:825)atorg.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)atorg.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)atorg.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)atorg.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)atorg.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)atorg.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)atorg.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)atorg.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)atorg.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)atorg.apache.maven.cli.MavenCli.execute(MavenCli.java:537)atorg.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)atorg.apache.maven.cli.MavenCli.main(MavenCli.java:141)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)atorg.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)atorg.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)atorg.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)atorg.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)...43moreCausedby:java.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:164)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:71)atorg.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:303)atorg.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:157)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)...56moreCausedby:java.lang.IllegalArgumentException:Nopropertyemployeefoundfortypeclasscom.nk.emis.basedata.entity.Permissionatorg.springframework.data.repository.query.parser.Property.<init>(Property.java:76)atorg.springframework.data.repository.query.parser.Property.<init>(Property.java:97)atorg.springframework.data.repository.query.parser.Property.create(Property.java:312)atorg.springframework.data.repository.query.parser.Property.create(Property.java:326)atorg.springframework.data.repository.query.parser.Property.create(Property.java:292)atorg.springframework.data.repository.query.parser.Property.from(Property.java:251)atorg.springframework.data.repository.query.parser.Property.from(Property.java:232)atorg.springframework.data.repository.query.parser.Part.<init>(Part.java:48)atorg.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:242)atorg.springframework.data.repository.query.parser.PartTree.buildTree(PartTree.java:101)atorg.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:77)atorg.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:56)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)...63more
解决方案三:
publicclassMyRepositoryImpl<T,IDextendsSerializable>extendsSimpleJpaRepository<T,ID>implementsMyRepository<T,ID>{privateEntityManagerentityManager;//Therearetwoconstructorstochoosefrom,eithercanbeused.publicMyRepositoryImpl(Class<T>domainClass,EntityManagerentityManager){super(domainClass,entityManager);//Thisistherecommendedmethodforaccessinginheritedclassdependencies.this.entityManager=entityManager;}publicvoidsharedCustomMethod(IDid){//implementationgoeshere}}
建议从Simple类继承实现类