Update: the following is using Spring Boot 2.1.0
I have a Spring Data repository and I am trying to provide some custom functionality to it, following the fragments example from the documentation.
So I've added an extra interface to the repository:
public interface UserRepository extends JpaRepository<User, Long>, UserExtraLogic {
User findByFirstNameAndLastName(String firstName, String lastName);
}
with this custom interface:
interface UserExtraLogic {
void ensureHasAccess();
}
and its implementation:
class UserExtraLogicImpl implements UserExtraLogic {
public void ensureHasAccess() {
}
}
The problem is that I would like to be able to use my repositories inside UserExtraLogicImpl, so that I can reuse query methods like findByFirstNameAndLastName without having to write them by myself with EntityManager. So I tried this:
class UserExrtaLogicImpl implements UserExtraLogic {
@Autowired
private UserRepository userRepository;
}
But then the application does not start. I get a NullPointerException, but I think it's just Spring getting into a cycle trying to resolve these dependencies.
Is what I'm trying to do possible? Is there another way to do this?