Mapstruct can be integrated with Webflux in a Spring Boot application by following these steps:
mapstruct
and mapstruct-processor
dependencies to the pom.xml
file.<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.2.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
<scope>provided</scope>
</dependency>
@Mapper
public interface PersonMapper {
PersonDto toDto(Person person);
Person toEntity(PersonDto personDto);
}
@MapperComponentModel
annotation to the mapping interface to enable Spring component model.@MapperComponentModel("spring")
public interface PersonMapper {
PersonDto toDto(Person person);
Person toEntity(PersonDto personDto);
}
@RestController
@RequestMapping("/api")
public class PersonController {
private final PersonMapper personMapper;
@Autowired
public PersonController(PersonMapper personMapper) {
this.personMapper = personMapper;
}
@GetMapping("/person/{id}")
public Mono<PersonDto> getPerson(@PathVariable String id) {
return personRepository.findById(id)
.map(personMapper::toDto);
}
@PostMapping("/person")
public Mono<Void> createPerson(@RequestBody Mono<PersonDto> personDtoMono) {
return personDtoMono
.map(personMapper::toEntity)
.flatMap(personRepository::save)
.then();
}
}
org.mapstruct.spring.mapstruct-spring-boot-starter
dependency.<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-spring-boot-starter</artifactId>
<version>1.4.2.Final</version>
</dependency>
By following these steps, Mapstruct can be integrated with Webflux in a Spring Boot application.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-02-03 11:00:00 +0000
Seen: 15 times
Last updated: Jun 16 '21
Is it possible to globally install System.Data.OleDb?
How to debug NextJS application in VSCode?
Why does the app shut down when switching to the Google Maps section in a Flutter application?
How can an application Manager be put in place to manage the system?
How can a Qt application detect a trigger triggered by a batch script?
How can I execute a React Native application on my Android device?
What conditions could cause Wildfly to automatically undeploy an EAR?
How can an application be run with parameters from the context menu?