Chapter 5: Complete Annotation Dictionary (A-Z)
Quick reference of all Spring Boot annotations, sorted alphabetically. For detailed code examples, see chapters 1 to 4.
A
| Annotation | Description |
|---|---|
| @ActiveProfiles | Activates specific Spring profiles for unit tests. Allows loading application-test.yml for example. |
| @After | (JUnit 4) Executes code after each test method. |
| @AfterClass | (JUnit 4) Executes code after all test methods in a class. |
| @AfterEach | (JUnit 5) Executes code after each test method. Replaces @After. |
| @Async | Executes a method asynchronously in a separate thread. Requires @EnableAsync. |
| @AutoConfigureDataJpa | Automatically configures JPA for a unit test. |
| @AutoConfigureJsonTesters | Automatically configures JSON serialization/deserialization tools for tests. |
| @AutoConfigureMockMvc | Automatically configures the MockMvc object for a unit test. |
| @AutoConfigureWebTestClient | Automatically configures the WebTestClient for WebFlux tests. |
| @Autowired | Automatically injects a dependency (Spring bean) into a class. Prefer constructor injection. |
B
| Annotation | Description |
|---|---|
| @Bean | Declares a method that returns an object managed by the Spring container. Used in @Configuration classes. |
| @Before | (JUnit 4) Executes code before each test method. |
| @BeforeClass | (JUnit 4) Executes code before all test methods in a class. |
| @BeforeEach | (JUnit 5) Executes code before each test method. Replaces @Before. |
C
| Annotation | Description |
|---|---|
| @Cacheable | Caches the result of a method. Subsequent calls return the cached result. |
| @CacheConfig | Configures cache settings (name, lifespan, max size) for an entire class. |
| @CacheEvict | Removes one or all cache entries when the method is called. |
| @CachePut | Updates the cache with the method result, never using the existing cache. |
| @CircuitBreaker | (Spring Cloud) Protects a method from repeated failures by limiting calls when the service is down. |
| @Column | Configures the mapping of a JPA property to a database column (name, nullable, unique, length). |
| @Component | Marks a class as a generic Spring bean, automatically detected by component scan. |
| @ComponentScan | Scans packages to automatically detect classes annotated with @Component, @Service, @Repository, etc. |
| @Conditional | Conditions the creation of a bean based on a custom condition. |
| @ConditionalOnClass | Creates a bean only if a specific class is present in the classpath. |
| @ConditionalOnMissingBean | Creates a bean only if no other bean of the same type already exists. |
| @ConditionalOnProperty | Creates a bean only if a property has a certain value in the configuration. |
| @Configuration | Marks a Spring configuration class containing @Bean methods. |
| @ConfigurationProperties | Binds a group of configuration file properties to a Java object (e.g., app.mail.host). |
| @Controller | Marks a class as a Spring MVC controller that returns views (HTML templates). |
| @ControllerAdvice | Defines a global advisor for all controllers (centralized exception handling, binding, etc.). |
| @CrossOrigin | Allows cross-origin HTTP requests (CORS) from specific domains or all domains. |
D
| Annotation | Description |
|---|---|
| @DataJpaTest | Specialized test that loads only the JPA layer (repositories, EntityManager, in-memory DB). |
| @DeleteMapping | Shortcut for @RequestMapping(method = DELETE). Maps a method to an HTTP DELETE request. |
| @Disabled | (JUnit 5) Temporarily disables a unit test without removing it from the code. |
E
| Annotation | Description |
|---|---|
| @EnableAsync | Enables asynchronous execution in the application. Necessary for @Async to work. |
| @EnableCaching | Enables caching in the application. Necessary for @Cacheable to work. |
| @EnableConfigurationProperties | Enables automatic binding of configuration properties to @ConfigurationProperties objects. |
| @EnableJms | Enables JMS (Java Message Service) support for messaging in the application. |
| @EnableJpaRepositories | Enables support for Spring Data JPA repositories. Automatically configured by Spring Boot. |
| @EnableScheduling | Enables task scheduling. Necessary for @Scheduled to work. |
| @EnableWebMvc | Enables Spring MVC configuration. Rarely necessary as Spring Boot enables it automatically. |
| @EnableWebSecurity | Enables custom Spring Security configuration. |
| @EnableMethodSecurity | Enables method-level security (@PreAuthorize, @PostAuthorize, @Secured). |
| @Entity | Marks a class as a JPA entity, mapped to a database table. |
| @Enumerated | Defines how a Java enum is stored in the DB: STRING (text) or ORDINAL (number). |
| @EventListener | Listens for Spring events (application startup, custom events, etc.). |
| @ExceptionHandler | Handles a specific exception in a controller or @ControllerAdvice. Returns a custom error response. |
| @ExtendWith | (JUnit 5) Extends test functionalities with extensions (e.g., SpringExtension, MockitoExtension). |
F
| Annotation | Description |
|---|---|
| @Fallback | (Spring Cloud) Provides a fallback method when a @CircuitBreaker method fails. |
| @FlywayTest | Tests Flyway database migrations in integration tests. |
| @Formula | (Hibernate) Defines a SQL-side calculated column, without a physical column in the database. |
G
| Annotation | Description |
|---|---|
| @GeneratedValue | Defines the automatic generation strategy for the primary key (IDENTITY, SEQUENCE, UUID, AUTO). |
| @GetMapping | Shortcut for @RequestMapping(method = GET). Maps a method to an HTTP GET request. |
I
| Annotation | Description |
|---|---|
| @Id | Marks a field as the primary key of a JPA entity. |
| @Import | Imports other configuration classes into a @Configuration class. |
| @InitBinder | Customizes data binding between HTTP requests and Java objects (conversion, validation, formatting). |
J
| Annotation | Description |
|---|---|
| @JoinColumn | Defines the foreign key column for a JPA relationship (@ManyToOne, @OneToOne). |
| @JoinTable | Defines the join table for a @ManyToMany relationship (table name, join columns). |
| @JmsListener | Defines a method that listens for JMS messages on a queue or topic. |
| @JsonFormat | Customizes JSON serialization format (dates, numbers). E.g., @JsonFormat(pattern = "yyyy-MM-dd"). |
| @JsonIgnore | Excludes a property from JSON serialization/deserialization. |
| @JsonInclude | Controls which properties are included in JSON (e.g., exclude null values). |
| @JsonProperty | Renames a property in JSON. E.g., @JsonProperty("full_name") for a fullName field. |
| @JsonSubTypes | Defines subtypes for polymorphic JSON deserialization. |
| @JsonTest | Specialized test for JSON serialization/deserialization only. |
| @JsonTypeInfo | Adds type information in JSON to allow polymorphic deserialization. |
| @JsonView | Filters JSON properties according to the requested view (e.g., public view vs admin view). |
L
| Annotation | Description |
|---|---|
| @Lazy | Delays bean initialization until its first use. Improves startup time. |
| @Lob | Indicates a Large Object field: CLOB (long text) or BLOB (binary). |
M
| Annotation | Description |
|---|---|
| @ManyToMany | Defines a many-to-many relationship between two JPA entities. Uses a join table. |
| @ManyToOne | Defines a many-to-one relationship. The "Many" side holds the foreign key. |
| @MessageMapping | (WebSocket/STOMP) Maps a method to a messaging destination. |
| @MessagingGateway | (Spring Integration) Defines a gateway interface for sending messages. |
| @MockBean | Replaces a Spring bean with a Mockito mock in a test. |
| @MockMvc | Injects a MockMvc instance to simulate HTTP requests in tests. |
| @ModelAttribute | Binds HTTP request parameters to a Java object. Also used to add attributes to the MVC model. |
| @Modifying | Indicates that a @Query method executes an UPDATE or DELETE (not a SELECT). |
N
| Annotation | Description |
|---|---|
| @NamedQuery | Defines a named JPQL query directly on an entity. |
| @NamedQueries | Groups multiple @NamedQuery on the same entity. |
O
| Annotation | Description |
|---|---|
| @OneToMany | Defines a one-to-many relationship between two JPA entities. The "One" side is the parent. |
| @OneToOne | Defines a one-to-one relationship between two JPA entities. |
| @Order | Defines the priority order of a bean. The smaller the number, the higher the priority. |
P
| Annotation | Description |
|---|---|
| @PatchMapping | Shortcut for @RequestMapping(method = PATCH). Partial update of a resource. |
| @PathVariable | Extracts a variable from the URL path. E.g., /users/\{id\} → @PathVariable Long id. |
| @PostAuthorize | Checks authorizations after method execution (can check the returned value). |
| @PostConstruct | Executes a method just after all bean dependencies are injected. |
| @PostMapping | Shortcut for @RequestMapping(method = POST). Creation of a new resource. |
| @PreAuthorize | Checks authorizations before method execution. Supports SpEL expressions. |
| @PreDestroy | Executes a method just before the bean is destroyed (cleanup, closing connections). |
| @Primary | Defines the default bean when multiple beans of the same type exist. |
| @Profile | Activates a bean or configuration only for certain profiles (dev, test, prod). |
| @PutMapping | Shortcut for @RequestMapping(method = PUT). Full replacement of a resource. |
Q
| Annotation | Description |
|---|---|
| @Qualifier | Specifies which bean to inject when multiple beans of the same type exist. |
| @Query | Defines a custom JPQL or native SQL query on a repository method. |
R
| Annotation | Description |
|---|---|
| @Repository | Marks a class as a data access layer. Enables SQL exception translation to Spring exceptions. |
| @RequestBody | Deserializes the HTTP request body (JSON) into a Java object. |
| @RequestHeader | Extracts the value of an HTTP header (Authorization, Content-Type, User-Agent, etc.). |
| @RequestMapping | Base annotation to map a URL to a controller or method. Can specify the HTTP method. |
| @RequestParam | Extracts a parameter from the query string. E.g., /search?name=Java → @RequestParam String name. |
| @RequestPart | Extracts a part of a multipart HTTP request (files, uploaded images). |
| @ResponseBody | Forces a method to return JSON/XML directly in the HTTP response body. |
| @ResponseStatus | Defines the HTTP status code returned by a method (200, 201, 204, 404, etc.) or an exception. |
| @RestClientTest | Specialized test for REST clients. Loads only the client configuration. |
| @RestController | Combination of @Controller + @ResponseBody. Each method returns JSON directly. |
| @RestControllerAdvice | Combination of @ControllerAdvice + @ResponseBody. Global exception handling for REST APIs. |
| @Retryable | (Spring Retry) Automatically retries a method in case of failure (e.g., network or DB error). |
| @RolesAllowed | (JSR-250) Specifies allowed roles for a method. Standard alternative to @Secured. |
S
| Annotation | Description |
|---|---|
| @Scheduled | Schedules periodic execution of a method (fixedRate, fixedDelay, cron). Requires @EnableScheduling. |
| @Scope | Defines the scope of a bean: singleton (default), prototype, request, session, application. |
| @Secured | Specifies required roles to access a method. Simpler than @PreAuthorize. |
| @SendTo | (WebSocket/STOMP) Specifies the response destination for a WebSocket message. |
| @Service | Marks a class as a business logic layer. Detected by component scan. |
| @SessionAttributes | Stores model attributes in the HTTP session between requests. |
| @SessionScope | Defines the scope of a bean as HTTP session (one bean per user session). |
| @SpyBean | Wraps a real bean with a Mockito spy in tests (real calls except those stubbed). |
| @SpringBootApplication | Application entry point. Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. |
| @SpringBootTest | Loads the full Spring context for integration tests. |
| @Sql | Executes SQL scripts before or after a test to prepare or clean the database. |
T
| Annotation | Description |
|---|---|
| @Table | Customizes the table name, schema, uniqueness constraints, and indexes for a JPA entity. |
| @Test | (JUnit) Marks a method as a unit test. |
| @TestConfiguration | Provides Spring configuration specific to tests (test beans, mocks). |
| @Timeout | (JUnit 5) Sets a maximum execution time for a test. The test fails if the time is exceeded. |
| @Transactional | Manages DB transactions. Commits on success, rolls back on exception. readOnly = true optimizes reads. |
| @TransactionalEventListener | Listens for a Spring event and executes it only after the transaction commit (or rollback). |
| @Transient | Excludes a field from JPA persistence (no database column). |
V
| Annotation | Description |
|---|---|
| @Valid | Enables Bean Validation on an object (@NotNull, @Size, @Email, etc.). |
| @Validated | Spring variant of @Valid with support for validation groups. |
| @Value | Injects a value from the configuration file. E.g., @Value("${app.name}"). Supports default values and SpEL. |
| @ValueSource | (JUnit 5) Provides input values to a parameterized test. |
W
| Annotation | Description |
|---|---|
| @WebFluxTest | Specialized test for WebFlux controllers (reactive programming). |
| @WebMvcTest | Specialized test that loads only the MVC controller layer (no DB, no real services). |
| @WebTestClient | Injects a WebTestClient to simulate HTTP requests in WebFlux tests. |
Validation Annotations (Bean Validation)
| Annotation | Description |
|---|---|
| @NotNull | The field cannot be null. |
| @NotEmpty | The field cannot be null or empty (String, Collection, Map). |
| @NotBlank | The field cannot be null, empty, or contain only spaces. |
| @Size(min, max) | The size must be between min and max (String, Collection). |
| @Min(value) | The numeric value must be greater than or equal to value. |
| @Max(value) | The numeric value must be less than or equal to value. |
| The field must be a valid email address format. | |
| @Pattern(regexp) | The field must match the given regular expression. |
| @Positive | The number must be strictly positive (> 0). |
| @PositiveOrZero | The number must be positive or zero (>= 0). |
| @Negative | The number must be strictly negative (< 0). |
| @Past | The date must be in the past. |
| @Future | The date must be in the future. |
| @DecimalMin | The decimal value must be greater than or equal to the minimum. |
| @DecimalMax | The decimal value must be less than or equal to the maximum. |
Statistics
In summary
This dictionary covers 120+ annotations distributed in:
- Core Spring: ~25 annotations (IoC, DI, configuration, lifecycle)
- Web / REST: ~20 annotations (mapping, parameters, responses, errors)
- Data / JPA: ~20 annotations (entities, relationships, queries, transactions)
- JSON / Jackson: ~7 annotations (format, filter, ignore)
- Security: ~7 annotations (config, authorization)
- Cache: ~5 annotations (cacheable, evict, put, config)
- Async / Scheduling: ~5 annotations
- Test: ~25 annotations (JUnit, Spring Test, mocks)
- Validation: ~15 annotations (Bean Validation)
- Messaging: ~5 annotations (JMS, WebSocket)
- Cloud / Resilience: ~3 annotations (CircuitBreaker, Retry, Fallback)