API and Microservices — JNTUK R20 (Job Oriented Course)
Prepared as exam-oriented, textbook-style notes covering Units I – V. Includes full concepts, definitions,
diagrams, example code, and sample questions with answers.
Contents:
1. Unit I: Spring 5 Basics
2. Unit II: Spring Boot
3. Unit III: Spring Data JPA with Boot
4. Unit IV: Web Services (SOAP & REST)
5. Unit V: Spring REST (Controllers, Validation, Security)
6. Sample Questions & Answers
UNIT I — Spring 5 Basics
Overview:
Spring is a lightweight, open-source framework for building Java applications. It provides
comprehensive infrastructure support for developing Java applications easily and rapidly. Spring
simplifies<br/>enterprise Java development by providing features like Inversion of Control (IoC),
Dependency Injection (DI), aspect-oriented programming (AOP), transaction management, and more.
Core Modules: Spring Core, Beans, Context, AOP, JDBC, ORM, Web, MVC.
IoC & DI: The IoC container manages object creation and dependencies. DI injects dependencies via
constructors or setters.
Example Java-based configuration:
@Configuration @ComponentScan("[Link]") public class AppConfig { @Bean public
MessageService messageService() { return new EmailService(); } }
UNIT II — Spring Boot
Overview: Spring Boot provides auto-configuration, starters, and embedded servers to simplify app
creation.
Example main class:
@SpringBootApplication public class DemoApplication { public static void main(String[]
args) { [Link]([Link], args); } }
UNIT III — Spring Data JPA with Boot
Overview: Spring Data JPA reduces boilerplate for data access. Use @Entity for models and
JpaRepository for repositories.
@Entity public class Product { @Id @GeneratedValue private Long id; private String name;
private Double price; // getters and setters } public interface ProductRepository extends
JpaRepository<Product, Long> { List<Product> findByName(String name); }
UNIT IV — Web Services (SOAP & REST)
Overview: SOAP uses XML/WSDL; REST uses HTTP/URIs and typically JSON. REST is stateless and
simpler.
Example REST controller:
@RestController @RequestMapping("/products") public class ProductController { @Autowired
ProductService service; @GetMapping("/{id}") public ResponseEntity<Product>
get(@PathVariable Long id) { return [Link](id).map(ResponseEntity::ok)
.orElse([Link]().build()); } }
UNIT V — Spring REST
Overview: Use @RestController, bind using @PathVariable, @RequestParam, @RequestBody;
validate with @Valid; handle exceptions with @ControllerAdvice.
@GetMapping("/search") public List<Product> search(@RequestParam String name) { return
[Link](name); }
Sample Questions & Answers
Q: What is Dependency Injection? A: DI is ...
Q: What is Spring Boot? A: Spring Boot is ...