I downloaded the following project and imported it into Visual Studio Code
:
https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example
I have a problem on the following class, when invoking: car.getName()
.
https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example/blob/d5c959162ed0f862a5dceb93f5957f92e052e062/server/src/main/java/com/okta/developer/demo/CoolCarController.java
which content is:
CoolCarController.java
package com.okta.developer.demo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.stream.Collectors;
@RestController
class CoolCarController {
private CarRepository repository;
public CoolCarController(CarRepository repository) {
this.repository = repository;
}
@GetMapping("/cool-cars")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<Car> coolCars() {
return repository.findAll().stream()
.filter(this::isCool)
.collect(Collectors.toList());
}
private boolean isCool(Car car) {
return !car.getName().equals("AMC Gremlin") &&
!car.getName().equals("Triumph Stag") &&
!car.getName().equals("Ford Pinto") &&
!car.getName().equals("Yugo GV");
}
}
here is also the content of:
Car.java
package com.okta.developer.demo;
import lombok.*;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Entity;
@Entity
@Getter @Setter
@NoArgsConstructor
@ToString @EqualsAndHashCode
public class Car {
@Id @GeneratedValue
private Long id;
private @NonNull String name;
}
As you can see on the image below, I'm getting the error:
[Java] The method getName() is undefined for the type Car
I think Visual Studio Code
doesn't understand the package: lombok
.
Any idea on how can I make Visual Studio Code
understand that package?
Thanks!
Open VS Code and press Ctrl + Shift + X to open extension manager. Type lombok and click install. Reload VS Code when asked.
Once you've installed the Extension Pack for Java, you can see the tips using the Java: Tips for Beginners command from the Command Palette in VS Code. Open the Command Palette (Ctrl+Shift+P) and type "java tips" to select the command.
Latest version of Lombok and/or IntelliJ plugin perfectly supports Java 11.
Lombok Dependency Note: If you're using a Spring Boot POM, Project Lombok is a curated dependency. Thus, you can omit the version (which will then be inherited from the Spring Boot parent POM).
Ok, Installing extension: Lombok Annotations Support for VS Code
(gabrielbb.vscode-lombok) did the trick.
If your project loads before installing this plugin Lombok Annotations Support for VS Code
, you can run this command in vscode to reload the project.
Press Command + shift + P
and execute:
Java: Clean Java language server workspace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With