Advanced Spring Boot Interview Questions for 5+ years of experience

#java # spring-boot

This post contains the advanced Spring Boot Interview Questions for 5+ years of experience

All Questions

1. What is the use of @PathVariable annotation?

Topic: spring-basics

Answer:

The @PathVariable method parameter annotation is used to indicate that a method parameter should be bound to the value of a URI template variable.

Usage in short:

  • to extract the value of the template variables 
  • assign their value to a method variable

See the usage below for the  @PathVariable in controller method:

@RequestMapping("/employee/{empId}", method=RequestMethod.GET)
public String findEmployee(@PathVariable String empId, Model model) {
  Employee emp = serice.findEmp(empId);  
  model.addAttribute("emp", emp);  
  return "displayResult"; 
}

The URI Template "/employee/{empId}" specifies the variable name empId. When the controller handles this request, the value of empId is set the value in the request URI.

Multiple @PathVariable annotations can be used to bind to multiple URI Template variables

Complexity: beginner

2. What is the @RestController annotation in Spring Boot

Topic: spring-basics

Answer:

Complexity: intermediate

3. What is the usage of @PathVariable annotation

Topic: spring-basics

Answer:

Complexity: intermediate

4. What is dependecy injection in Spring?

Topic: spring-basics

Answer:

Complexity: intermediate

5. Can you explain the flow how to fetch the contents of the employee table and send it back to the frontend? How do you achieve this in Spring

Topic: spring-basics

Answer:

Complexity: intermediate

#java # spring-boot