I am trying to set up lombok in my sts.
So far I have done these steps: I downloaded the lambok jar file. I ran the file and specified the path for sts.exe and then clicked on install. I have added the required dependencies in my pom.xml
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
I have also edited my sts.ini file. After installation of lambok.jar following line was already there at the end pf the file
-javaagent:E:\JAVA SOFTWARES\spring-tool-suite-3.9.8.RELEASE-e4.11.0-win32-x86_64\sts-bundle\sts-
3.9.8.RELEASE\lombok.jar
so I moved it next to
-vmargs
Then, I cleaned my project. I have also updated my project. Closed sts and then ran my application again. But it is still not recognizing the getters in my file. It produces the following error.
The method getFirstname() is undefined for the type Student
Student.java:
package com.crud.msstudent.models;
import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
@Getter
@Setter
@Accessors(chain=true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "student")
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@NotEmpty(message = "First name is required")
private String firstname;
@NotEmpty(message = "Last name is required")
private String lastname;
@Column(nullable = true, name = "email")
private String email;
}
The error is being shown in my StudentController.java file. Following is some of the code:
@PutMapping(value="/students/{id}")
public Student updateStudent(@PathVariable("id") @Min(1) int id, @Valid
@RequestBody Student newstd) {
Student stdu = studentservice.findById(id)
.orElseThrow(()->new
StudentNotFoundException("Student with "+id+" is Not Found!"));
stdu.setFirstname(newstd.getFirstname());
stdu.setLastname(newstd.getLastname());
stdu.setEmail(newstd.getEmail());
return studentservice.save(stdu);
}
@DeleteMapping(value="/students/{id}")
public String deleteStudent(@PathVariable("id") @Min(1) int id) {
Student std = studentservice.findById(id)
.orElseThrow(()->new
StudentNotFoundException("Student with "+id+" is Not Found!"));
studentservice.deleteById(std.getId());
return "Student with ID :"+id+" is deleted";
}
Please tell me what am I missing?