1. Spring Boot Core Annotations
-
@SpringBootApplication - Entry point of a Spring Boot application (combines
@Configuration
,@EnableAutoConfiguration
,@ComponentScan
). -
@EnableAutoConfiguration - Automatically configures Spring Boot based on dependencies in the classpath.
-
@Configuration - Marks a class as a source of bean definitions.
-
@ComponentScan - Scans the specified package for Spring beans.
-
@Value - Injects a value into a field from properties or environment variables.
-
@Bean - Declares a bean in a configuration class.
-
@Component - Marks a class as a Spring-managed component.
-
@Service - A specialization of
@Component
, used for service layer classes. -
@Repository - A specialization of
@Component
, used for DAO classes. -
@Controller - Marks a class as a Spring MVC controller.
-
@RestController - Combines
@Controller
and@ResponseBody
for RESTful services. -
@ConfigurationProperties - Binds external configuration properties to a POJO.
-
@Import - Imports one or more configuration classes.
-
@PropertySource - Specifies the location of an additional property file.
-
@ImportResource - Imports XML configuration into the Spring context.
-
@EnableScheduling - Enables scheduling support for tasks.
-
@EnableAsync - Enables asynchronous method execution using
@Async
. -
@SpringBootTest - Used for integration testing with Spring Boot.
-
@TestConfiguration - A configuration class used in tests.
-
@EnableAspectJAutoProxy - Enables AspectJ-based AOP support.
2. Spring Dependency Injection (DI) Annotations
-
@Autowired - Marks a dependency to be injected automatically.
-
@Qualifier - Specifies which bean to inject when multiple candidates exist.
-
@Inject - Java standard for dependency injection (similar to
@Autowired
). -
@Resource - Injects a bean by name.
-
@Primary - Marks a bean to be the primary bean when there are multiple candidates.
-
@Named - A Java EE alternative to
@Component
for DI. -
@MockBean - Mocks a Spring bean in testing.
-
@InjectMocks - Injects mocked dependencies into the object under test.
-
@Mock - Creates a mock of a class for unit testing.
-
@Spy - Creates a spy object to track method calls in testing.
3. Spring Security Annotations
-
@EnableWebSecurity - Enables Spring Security for the application.
-
@Secured - Specifies that a method or class can only be accessed by users with specific roles.
-
@PreAuthorize - Defines security expressions for method-level access control.
-
@PostAuthorize - Defines security checks after method execution.
-
@RolesAllowed - Restricts access to methods based on roles.
-
@EnableGlobalMethodSecurity - Enables method-level security annotations such as
@Secured
and@PreAuthorize
. -
@EnableOAuth2Sso - Enables OAuth2 Single Sign-On support.
-
@EnableGlobalAuthentication - Enables global authentication.
-
@EnableOAuth2Login - Enables OAuth2 login functionality.
-
@PreFilter - Filters parameters before method execution for security.
4. Spring Data JPA Annotations
-
@Entity - Marks a class as a JPA entity.
-
@Table - Specifies the table name for an entity.
-
@Id - Specifies the primary key of the entity.
-
@GeneratedValue - Specifies how the primary key is generated.
-
@Column - Maps a field to a database column.
-
@ManyToOne - Defines a many-to-one relationship.
-
@OneToMany - Defines a one-to-many relationship.
-
@OneToOne - Defines a one-to-one relationship.
-
@ManyToMany - Defines a many-to-many relationship.
-
@JoinColumn - Specifies the join column for relationships.
-
@JoinTable - Defines a join table for a many-to-many relationship.
-
@Transactional - Marks methods or classes as transactional.
-
@Query - Defines custom queries in repository methods.
-
@TransactionalEventListener - Listens for transactional events.
-
@Embeddable - Marks a class as embeddable in entities.
-
@EmbeddedId - Specifies a composite primary key.
-
@OrderBy - Specifies the order of results in a query.
-
@ElementCollection - Defines a collection of simple values or embeddable objects.
-
@NotFound - Specifies how to handle a missing relationship in JPA.
-
@Fetch - Defines how related entities are fetched (eager/lazy).
5. Spring Web Annotations
-
@RequestMapping - Maps HTTP requests to handler methods.
-
@GetMapping - Maps HTTP GET requests to handler methods.
-
@PostMapping - Maps HTTP POST requests to handler methods.
-
@PutMapping - Maps HTTP PUT requests to handler methods.
-
@DeleteMapping - Maps HTTP DELETE requests to handler methods.
-
@PatchMapping - Maps HTTP PATCH requests to handler methods.
-
@RequestParam - Binds request query parameters to method parameters.
-
@PathVariable - Binds path variables in the URL to method parameters.
-
@RequestBody - Binds HTTP request body to method parameters.
-
@ResponseBody - Marks method return values to be written to the HTTP response body.
-
@RequestHeader - Binds HTTP request headers to method parameters.
-
@CookieValue - Binds cookies to method parameters.
-
@RequestMapping(path = "/path/{id}") - Maps path variables in the URL to method parameters.
-
@ModelAttribute - Binds request parameters or model attributes to method parameters.
-
@ResponseStatus - Marks a method or exception handler with a specific HTTP status code.
-
@ExceptionHandler - Handles exceptions thrown in controller methods.
-
@RestControllerAdvice - Provides centralized exception handling for REST controllers.
-
@SessionAttributes - Binds model attributes to the HTTP session.
-
@CrossOrigin - Enables Cross-Origin Resource Sharing (CORS) for controller methods.
-
@EnableWebSecurity - Enables Spring Security for your web application.
6. Spring WebFlux Annotations
-
@EnableWebFlux - Enables Spring WebFlux for reactive programming.
-
@RestController - A combination of
@Controller
and@ResponseBody
. -
@RequestMapping - Maps HTTP requests to handler methods.
-
@GetMapping / @PostMapping - HTTP method-specific mappings.
-
@ResponseBody - Marks method return values to be written to the HTTP response body.
-
@RequestBody - Binds HTTP request body to a method parameter.
-
@PathVariable - Binds path variables to method parameters.
-
@RequestParam - Binds request query parameters to method parameters.
-
@RequestHeader - Binds request headers to method parameters.
-
@WebFluxTest - Focuses on testing WebFlux controllers in isolation.
7. Spring Actuator Annotations
-
@Endpoint - Defines a custom actuator endpoint.
-
@ReadOperation - Marks a method as a read operation in a custom endpoint.
-
@WriteOperation - Marks a method as a write operation in a custom endpoint.
-
@DeleteOperation - Marks a method as a delete operation in a custom endpoint.
-
@HealthIndicator - Provides a custom health check for the actuator.
-
@Sensitive - Marks data as sensitive and excludes it from actuator endpoints.
-
@AuditEvent - Defines custom audit events.
-
@MetricTag - Adds tags to metrics in Spring Actuator.
-
@EnableActuator - Enables Spring Boot Actuator for monitoring and management.
-
@NonNull - Used for marking a field or method argument that cannot be
null
.
8. Spring AOP (Aspect-Oriented Programming) Annotations
-
@Aspect - Marks a class as an aspect for AOP.
-
@Before - Defines advice to be executed before a method execution.
-
@After - Defines advice to be executed after a method execution.
-
@AfterReturning - Defines advice that runs after a method completes successfully.
-
@AfterThrowing - Defines advice that runs if a method throws an exception.
-
@Around - Defines advice that wraps around a method execution.
-
@DeclareParents - Used to introduce new functionality to a class (aspect).
-
@Order - Specifies the order of advice execution.
-
@AroundAdvice - Defines an around advice for method execution.
-
@DeclareError - Introduces error handling into classes.
9. Spring Testing Annotations
-
@SpringBootTest - Loads the full application context for integration testing.
-
@WebMvcTest - Focuses on testing Spring MVC controllers.
-
@DataJpaTest - Focuses on testing JPA repositories.
-
@MockBean - Mocks a Spring bean for testing purposes.
-
@TestConfiguration - Declares a configuration class for testing.
-
@BeforeEach / @AfterEach - Set up and tear down methods before/after each test.
-
@BeforeAll / @AfterAll - Set up and tear down methods before/after all tests.
-
@ContextConfiguration - Specifies context configuration for tests.
-
@ActiveProfiles - Activates a specific Spring profile for testing.
-
@Transactional - Marks a test to run within a transaction, automatically rolling back after test execution.
10. Spring Validation Annotations
-
@NotNull - Ensures that a field is not
null
. -
@NotEmpty - Ensures that a string, collection, or array is not empty.
-
@NotBlank - Ensures that a string is not blank (doesn't allow only whitespace).
-
@Size - Ensures the size of a string, collection, or array is within a specified range.
-
@Min / @Max - Ensures the value of a number is within the specified range.
-
@Email - Ensures the value is a valid email format.
-
@Pattern - Ensures that the string matches a given regular expression.
-
@Future / @Past - Ensures that a date or time is in the future or past.
-
@AssertTrue / @AssertFalse - Ensures that a boolean field is
true
orfalse
. -
@DecimalMin / @DecimalMax - Ensures that a decimal value is within the specified range.