Created
December 7, 2011 14:58
-
-
Save jankronquist/1443114 to your computer and use it in GitHub Desktop.
Autowiring Morphia entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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