Hi!
I'm trying to do some "dynamic" injection using Spring. What the heck I mean by dynamic? I have a base abstract Dao class that has a generic type (which means the Model) nad has all basic (and even some advanced) persistence operations. Something like this:
The problem is, for simple CRUD operations I have to create "empty" Daos like this:Code:public abstract class Dao<M extends PersistentModel> { // a bunch of methods: insert, update, findAll, findByExample, etc }
So, I want to achieve the following: if a Dao is not present for some model, create an anonymous implementation automatically and make it available for injection.Code:@Repository public class ProductDao extends Dao<Product> { // no methods needed }
Suppose this service class and that the ProductDao above does not exist:
Did you guys get it? Can someone point me in the right direction? I'm looking at BeanFactory, FactoryBean, PostProcessor but no success until now.Code:@Service public class ProductService { @Autowired private Dao<Product> dao; // the bean is not found, create a new repository implementation and inject }
Thanks in advance!


Reply With Quote