如何结合Guice和Mapstruct? [英] How can i combine Guice and Mapstruct?

查看:106
本文介绍了如何结合Guice和Mapstruct?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用球衣和Guice DI,并且我想使用Mapstruct界面带有 @Inject 批注.那么有什么方法可以迫使Guice自动装配Mapstruct接口实现?

I'm using jersey and Guice DI and I want to use Mapstruct interfaces with @Inject annotation. So is there some way to force Guice to autowire Mapstruct interface implementations ?

推荐答案

您可以使用 @Mapper(componentModel ="jsr330")配置要使用JSR 330注释进行注释的Mappers的实现..您可以在 参考文档中找到更多信息.> .

You can configure the implementations of the Mappers to be annotated with JSR 330 annotation by using @Mapper(componentModel = "jsr330"). You can find more information in the reference documentation.

然后可以将Mapper接口与模块中的实现类绑定.

You can then bind the Mapper interface with the implementation class in your modules.

绑定它们的一种方法是使用Guice 链接绑定:

One way to bind them is to use Guice Linked Bindings:

bind(MyDtoMapper.class).to(MyDtoMapperImpl.class)

绑定它们的另一种方法是使用实例绑定:

Another way to bind them is to use Instance Bindings:

bind(MyDtoMapper.class).toInstance(MyDtoMapper.INSTANCE)

这篇关于如何结合Guice和Mapstruct?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆