简体   繁体   English

将Spring用作Morphia的对象工厂

[英]Use Spring as object factory for Morphia

I need to inject some fields to objects loaded from Mongo via Morphia using @Autowired annotations. 我需要使用@Autowired批注向通过Morphia从Mongo加载的对象注入一些字段。 I found an example how that's made with Guice: 我找到了一个示例,它是如何用Guice制作的:

Injector injector = Guice.createInjector(...);
MapperOptions options = injector.getInstance(Morphia.class)
        .getMapper()
        .getOptions();
options.setObjectFactory(new GuiceObjectFactory(
    options.getObjectFactory(),
    injector
));

So they use GuiceObjectFactory . 因此,他们使用GuiceObjectFactory Is there anything alike in Spring? 春天有什么相似之处吗?

Not included in Morphia but the implementation is pretty straightforward. 不包含在Morphia中,但是实现非常简单。 Here you can see what's happening for Guice. 在这里,您可以了解Guice的情况。 Other than asking the injector to create the instance, there's not much that really needs to happen. 除了要求injector创建实例之外,没有什么真正需要发生的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM