dependency injection - Spring 4 @Autowired Morphia -
how autowire instance of morphia
can have injected instead of recreating every time across controllers?
@controller public class teamcontroller { @autowired private mongotemplate mongotemplate; @autowired morphia morphia; … }
i found this article getting error using code there. seems odd me inject such simple object controllers have extend abstractentityinterceptor
in of them. spring version 4.0.
you don't need special make work. following code configuration (i assuming using java config, if not corresponding xml if easy write):
@bean public morphia morphia() { final morphia morphia = new morphia(); //add mappings //add converters //whatever else return mophia; }
you able use @autowired morphia morphia
inside spring beans, including of course teamcontroller
.
the tutorial following different because shows how inject morphia
entity not spring bean.
Comments
Post a Comment