Skip to content
Advertisement

Lombok annotations has no effect

I have a spring boot app 2.0.5.RELEASE with a lombok dependency for version 1.18.2 with scope set to provided.

An exmaple:

@RestController
@RequestMapping("/users")
@AllArgsConstructor
public class UserController {

    private static final UserMapper mapper = Mappers.getMapper(UserMapper.class);

    private UserRepository repository;//It's null, nothing gets injected

    @GetMapping("/")
    public ResponseEntity<List<UserDTO>> getUsers() {

        final List<User> users = (List<User>) repository.findAll();

        return new ResponseEntity<>(users.stream()
                .map(mapper::toDto)
                .collect(Collectors.toList()), HttpStatus.OK);
    }
}

In that case I’m getting an error as repository field is null. When I remove lombok @AllArgsConstructor and put it directly:

public UserController(UserRepository repository) {
    this.repository = repository;
}

Then it works, a proper component is injected in the repository field. The same situation is for UserDTO class. It’s definied:

@Getter @Setter
public class UserDTO {

    private int id;
    private String firstName;
    private String lastName;
}

Jackson is not able to find getters and throws an exception. Everything works fine if getters are created “normally” (without 3rd party libs).

What am I doing wrong? Why lombok is not generating things it should?

Advertisement

Answer

I fixed it by ticking the “Enable annotation processing” checkbox in Settings->Compiler->Annotation Processors.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement