2017-12-25 5 views
0

変換フィールドには、春のコンポーネントクラスと通常のクラスを使用する必要があります。mapstructでspringコンポーネントとnormalクラスを一緒に使う方法は?

以下でこのマッパー:

@Mapper(componentModel = "spring", uses = { ImagesConverter.class, DateTimeConvertor.class, IntEnumConverter.class, 
    DownloadModelHelper.class }, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) 
public interface PictureMapper { 
PictureMapper TRANSLATOR = Mappers.getMapper(PictureMapper.class); 

@Mappings({ @Mapping(source = "picture.img", target = "downloadModel"), 
     @Mapping(source = "picture.id", target = "pictureId"), 
     @Mapping(source = "galleryPicture.id", target = "galleryPictureID") }) 
PictureModel entityToModel(Picture entity); 

@Mapping(source = "pictureId", target = "picture") 
Picture modelToEntity(PictureModel model); 

List<PictureModel> entitiesToModels(List<Picture> entityList); 

List<Picture> modelsToEntities(List<PictureModel> modelList); 

}

ImagesConverterとDateTimeConverterはバネ部材クラスは@Componentの使用です。

ただし、IntEnumConverterとDownloadModelHelperは通常のクラスです。

開始春ブーツがエラーを以下の取得:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pictureMapperImpl': Unsatisfied dependency expressed through field 'downloadModelHelper': No qualifying bean of type [ir.pt.discountnetwork.commons.tools.DownloadModelHelper] found for dependency [ir.pt.discountnetwork.commons.tools.DownloadModelHelper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations 

mapstructで一緒に春の構成要素と通常のクラスを使用する方法?

+0

私はDownloadModelHelperもスプリングコンポーネントまたはBeanにする必要があると思いますが、これはそうですか? –

+0

DownloadModelHelperは別のプロジェクトの通常のクラスです。このクラスに@componentアノテーションを追加することはできません –

+0

@bean downloadModelHelper.classという設定でこのように使用できます。 –

答えて

0

おそらく、あなたはそれを行うことはできません。 SpringはJavaクラスを初期化します。コンポーネントを使用してスプリングコンテナ内に配置するか、手動で初期化します。

関連する問題