Core Spring Annotations
Component Annotations
@Component - Generic component detected by component scanning
@Service - Business service logic component
@Repository - Data access component, adds exception translation
@Controller - Web controller component
@RestController - Combines @Controller and @ResponseBody
Configuration Annotations
@Configuration - Marks a class as a source of bean definitions
@bean - Declares a method's return value as a bean
@ComponentScan - Defines packages to scan for components
@Autowired - Auto-wires dependencies (constructor, setter, field)
@Qualifier - Specifies which bean to autowire when multiple options exist
@Value - Injects values from properties files
@PropertySource - Specifies location of properties files
Boot-Specific Annotations
@SpringBootApplication - Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan
@EnableAutoConfiguration - Enables Spring Boot's auto-configuration
@ConfigurationProperties - Binds external properties to a class
Web Annotations
Request Handling
@RequestMapping - Maps HTTP requests to handler methods
@GetMapping - Shortcut for @RequestMapping(method = GET)
@PostMapping - Shortcut for @RequestMapping(method = POST)
@PutMapping - Shortcut for @RequestMapping(method = PUT)
@DeleteMapping - Shortcut for @RequestMapping(method = DELETE)
@PatchMapping - Shortcut for @RequestMapping(method = PATCH)
Request Parameters
@RequestParam - Binds request parameters to method parameters
@PathVariable - Binds URI template variables to method parameters
@RequestBody - Binds the HTTP request body to an object
@RequestHeader - Binds request headers to method parameters
@ResponseBody - Indicates the return value should be bound to the web response body
@ResponseStatus - Marks methods with a specific HTTP response status code
Data Access Annotations
JPA Annotations
@Entity - Marks a class as a JPA entity
@Table - Specifies the table for an entity
@id - Marks a field as the primary key
@GeneratedValue - Configures the way primary keys are generated
@column - Specifies column mapping
@Transient - Marks a field to be ignored by the persistence provider
Spring Data Annotations
@Transactional - Declares transaction boundaries
@Query - Defines a custom query for a repository method
@Modifying - Indicates a query method should be an update operation
Testing Annotations
@SpringBootTest - Bootstrap the full application context for tests
@WebMvcTest - Test Spring MVC components with a limited context
@DataJpaTest - Test JPA components
@MockBean - Add mock objects to Spring context
@SpyBean - Add spy objects to Spring context
@AutoConfigureMockMvc - Auto-configure MockMvc
Aspect-Oriented Programming
@aspect - Declares a class as an aspect
@Pointcut - Defines a reusable pointcut expression
@Before - Advice executed before the pointcut
@After - Advice executed after the pointcut
@Around - Advice that surrounds the pointcut
Top comments (0)