Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Autowiring Morphia entities
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import com.google.code.morphia.AbstractEntityInterceptor;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.mapping.Mapper;
import com.mongodb.DBObject;
public class SpringAutowiringEntityInterceptor extends AbstractEntityInterceptor {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private Morphia morphia;
@PostConstruct
public void postConstruct() {
morphia.getMapper().addInterceptor(this);
}
@Override
public void preLoad(Object ent, DBObject dbObj, Mapper mapr) {
applicationContext.getAutowireCapableBeanFactory().autowireBean(ent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.