Make sure your Main.**class** should be on top of your controllers. In case of the following example:
Main.class containing:
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
EmployeeController.**class** containing:
@RestController
public class EmployeeController {
@InitBinder
public void setAllowedFields(WebDataBinder dataBinder) {
dataBinder.setDisallowedFields("id");
}
@RequestMapping(value = "/employee/save", method = RequestMethod.GET)
public String save(){
Employee newEmp = new Employee();
newEmp.setAge(25);
newEmp.setFirstName("Pikachu");
newEmp.setId(100);
return "Name: " + newEmp.getFirstName() + ", Age: " + newEmp.getAge() + ", Id = " + newEmp.getId();
}
}
If your main class is in the root folder, just like this path: ***{projectname}/src/main/java/main*** then make sure your controllers below your Main class. For example ***{projectname}/src/main/java/main/controllers***.