I am trying to create an instance of my custom repository post initialization. The goal is that I give the class (PineappleRepository.class
) and it returns the object (PineappleRepository
).
Here the Custom Repository:
public interface FoodRepository<T extends FoodEntity> extends JpaRepository<T, UUID>, FoodRepositoryCustom {
}
public interface FoodRepositoryCustom {
List<FoodEntity> executeQuery(Map<String, String> query);
}
@Repository("Repo")
public class FoodRepositoryCustomImpl implements FoodRepositoryCustom {
private final EntityManager em;
public FoodRepositoryCustomImpl(EntityManager em) {
this.em = em;
}
@Override
public List<FoodEntity> executeQuery(Map<String, String> query) {
// Boring code
return new List<>();
}
}
Here is a wacky form of java sudo code, of what I am roughly looking for:
public <F extends FoodEntity> FoodRepository<F> getFoodRepository(Class<? extends FoodRepository<F>> clazz) {
// Perform magical generation of FoodRepository<F>
return foodRepository;
}
Any help is much appreciated, -AwesomeDude091
Edit: ApplicationContext or autowired will not work as the idea is that this repository is initalized post init. So outside of the Repo Scan, etc.