在mapstruct映射器中设置@component bean名称

问题描述 投票:0回答:1

我知道我可以创建一个这样的映射器:

@Mapper(componentModel="spring")
public interface MyMapper{

这将导致:

@Component
public class MyMapperImpl{

如何设置获取的bean名称:

@Component("name")
public class MyMapperImpl{
mapstruct
1个回答
3
投票

目前不支持此功能。这是为此功能请求的问题 mapstruct/mapstruct#1427

根据您的名称的外观,您可以使用自定义

AnnotationBeanNameGenerator
来生成组件扫描的映射器。

从 MapStruct 1.6(1.6.0.Beta1 已经发布)开始,可以使用新的

@AnnotateWith

例如

@AnnotateWith(value = Service.class, elements = @Element(strings = "myMapperV2")
@Mapper(componentModel="spring")
public interface MyMapper {
    // ...
}
© www.soinside.com 2019 - 2024. All rights reserved.