"BAEL-3407: Add examples for injecting Spring components in MapStruct" (#10778)
Co-authored-by: Krzysztof Woyke <krzysztof.woyke.sp@lhsystems.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.mapper;
|
||||
|
||||
import com.baeldung.dto.SimpleSource;
|
||||
import com.baeldung.entity.SimpleDestination;
|
||||
import com.baeldung.service.SimpleService;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public abstract class SimpleDestinationMapperUsingInjectedService {
|
||||
|
||||
@Autowired
|
||||
protected SimpleService simpleService;
|
||||
|
||||
@Mapping(target = "name", expression = "java(simpleService.enrichName(source.getName()))")
|
||||
public abstract SimpleDestination sourceToDestination(SimpleSource source);
|
||||
|
||||
public abstract SimpleSource destinationToSource(SimpleDestination destination);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user