Spring Boot 2.x JPA 不能够添加自定义Repository
升级Spring Boot版本后出现了大量的问题,升级到新版的Spring data JPA 会报错:
java1
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostAPI': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostRepositoryImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostRepository': Cannot create inner bean '(inner bean)#9af3bdd' of type [org.springframework.data.repository.core.support.RepositoryFragmentsFactoryBean] while setting bean property 'repositoryFragments'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#9af3bdd': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostRepositoryCustomImplFragment': Cannot resolve reference to bean 'sysPostRepositoryCustomImpl' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostRepositoryCustomImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysPostRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException
解决办法是需要在自定义的仓库类上,添加@NoRepositoryBean注解:
java1 2 3 4 5
@NoRepositoryBean public interface SysPostRepositoryCustom { ...... }
问题详情参考:
https://stackoverflow.com/questions/44831103/spring-boot-jpa-unable-to-add-custom-repository/