Announcement Announcement Module
Collapse
No announcement yet.
Spring Data + Dynamically Instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data + Dynamically Instance

    Hi everybody

    I am using the great Spring Data for data access on my application. Today I work generically this way:

    Example of a generic crud service

    Code:
    public class GenericCrudService<T, J extends Serializable> {
    	@Autowired
    	JpaRepository<T, J> dao;
    }
    It works great, I have no problems with it.

    The question is that, now I need some way to create the JpaRepository without know the type of the class.

    I am in na final class, cannot add <T,J> parameters e need something like the code below where I receive the class types from a parameter.

    Code:
    Class<?> T = Class.forName(param1);
    Class<?> J = Class.forName(param2);
    JpaRepository<Object, Serializable> teste = JpaRepositoryFactory.create(param1, param2);
    Obviously JpaRepositoryFactory does not exist, this code was just to figure what I really need. Is there any way to do something like this?

    Thank you





    [/code]
Working...
X