user3529850
user3529850

Reputation: 976

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?

Upvotes: 2

Views: 4612

Answers (3)

SwarupCode
SwarupCode

Reputation: 11

Apart from other answers to enable annotation processing in Intellij IDE, we need to add a plugin to make the IDE understand Lombok Project. Install the Lombok plugin: Settings > Plugins > Lombok.

Upvotes: 1

hbib
hbib

Reputation: 1

Settings->Build/Execution/Deployment - > Compiler->Annotation Processors -> Enable Annotation Processor ckeck

Upvotes: 0

GauravRai1512
GauravRai1512

Reputation: 844

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

Upvotes: 4

Related Questions