Annotations
Common Framework Annotations
Learn common enterprise annotations used in Spring, JPA, Jackson, and Lombok.
Interview: Tests practical application: mapping database mappings (@Entity, @Id) and dependency injection tags.
Enterprise Java frameworks use annotations to implement Inversion of Control (IoC), Object-Relational Mapping (ORM), and serialization rules.
Core Idea
Enterprise frameworks leverage reflection at startup to inspect annotations and configure system behavior.
Why It Matters
Using framework annotations replaces thousands of lines of manual configuration, speeding up development.
Interview Lens
Tests understanding of JPA lifecycle annotations and Spring's bean configuration mappings.
Key Framework Tags
JPA / Hibernate (ORM)
@Entity: Marks a class as a database table projection.@Id: Specifies the primary key field.
Spring Boot (DI & Routing)
@Autowired: Triggers Dependency Injection of a bean.@RestController: Exposes class methods as HTTP REST endpoints.
Code Walkthrough
This entity demonstrates using JPA and Spring annotations together.
Interview-Relevant Information
Q: How does Spring Boot process @Autowired at startup?
Answer: Spring Boot scans the classpath for classes annotated with component stereotypes (like @Component or @Service). It instantiates these classes as Beans inside its IoC container, then uses Reflection to inject them into fields or constructors marked with @Autowired.
Quick Checklist
What is Dependency Injection? Which annotation defines a primary key in JPA? If yes, you understand framework annotations.
Use Cases
Configuring dependency routing in web services.
Declaring data mappings in JPA database tables.
Common Mistakes
Using @Autowired on fields instead of constructors (constructor injection is preferred for testability and immutability).
Forgetting to annotate a class with a stereotype (like @Service), causing Spring to fail to locate and load the bean.