java - Spring autowire repository by entity type -
all of entities implement interface ientity
.
i created interface repositories so:
@norepositorybean public interface irepository<t extends ientity> extends crudrepository<t, long>
i have generic code takes in entity type , needs repository entity type. i'm trying use spring's applicationcontext.getbean(class<t>)
method fetch appropriate repository entity passed in this:
@autowired applicationcontext context; irepository<? extends ientity> getrepository(final ientity entity) { class<irepository<? extends ientity>> clazz = ???????; return context.getbean(clazz); }
how tell class need autowire based on?
Comments
Post a Comment