I am looking for a way to inject certain properties via Spring in a bean that is loaded from the DB by Hibernate.
E.g.
class Student {
int id; //loaded from DB
String name; //loaded from DB
int injectedProperty; //Inject via Spring
}
Can I configure Spring so that whenever Hibernate creates objects of class Student, some properties as defined in some applicationContext file are injected with the object creation?
There is a facility for this, using AspectJ class weaving with the
@Configurableannotation. This will auto-wire anynewinstance of an annotated class with Spring dependencies, including objects instantiated via reflection using the likes of Hibernate.It does require some class-loading magic, and so depends on compatibility with your server platform.