-1

So I have a mapstruct mapper in my app, which has source to destination pojo mappings. I perform some logic inside the @AfterMapping class using the value from the @Value like below. But it seems like the value is not being fetched and hence its set as null What am I missing here?

@Mapper
abstract class Student{

@Value("${spring.application.name}")
String appName;

abstract StudentModel convert(StudentDTO Studentdto);

@AfterMapping
void postConvert(@MappingTarget StudentModel studentmodel,StudentDTO studentDTO) {
studentmodel.setName(appName)

}

application.yml

spring:
   application:
       name: ABC
ghostrider
  • 2,046
  • 3
  • 23
  • 46

1 Answers1

0

I have never used mapstruct, but spring injects values only into beans (like @Service, @Repository, @RestController or @Component). Your student class is not a bean, moreover it is an abstract class. Probably you need to pass appName from some service and use @Value there