Módulo 17: Referência Completa das Anotações Spring Boot
Objetivos do Módulo
Este módulo é uma referência exaustiva de todas as anotações Spring Boot que você encontrará no desenvolvimento. Ele cobre:
- As anotações do núcleo do Spring (IoC, DI, configuração)
- As anotações Web e REST
- As anotações de persistência (JPA/Hibernate)
- As anotações de segurança, teste e anotações avançadas
Plano do Módulo
| # | Capítulo | Conteúdo |
|---|---|---|
| 1 | Anotações Core Spring | @Component, @Service, @Repository, @Configuration, @Bean, @Autowired, @Value, @Profile, @Scope, @Conditional... |
| 2 | Anotações Web e REST | @RestController, @RequestMapping, @GetMapping, @PostMapping, @RequestBody, @PathVariable, @ResponseStatus, @CrossOrigin... |
| 3 | Anotações Data e JPA | @Entity, @Table, @Id, @GeneratedValue, @Column, @OneToMany, @ManyToOne, @Query, @Transactional, @Modifying... |
| 4 | Anotações Security, Teste e Avançadas | @EnableWebSecurity, @PreAuthorize, @SpringBootTest, @MockBean, @Scheduled, @Async, @EnableCaching, @Validated... |
| 5 | Dicionário Completo A-Z | 120+ anotações classificadas em ordem alfabética com descrições curtas — referência rápida |
Como Utilizar Este Módulo
Guia de referência
Este módulo foi projetado como um dicionário de anotações. Você não precisa lê-lo do início ao fim. Use como referência quando encontrar uma anotação desconhecida ou quando estiver procurando a anotação adequada para sua necessidade.
Caminho de uma Requisição HTTP no Spring Boot
Visão geral: do Cliente ao Banco de Dados
Fluxo detalhado com anotações
Arquitetura em camadas e suas anotações
Exemplo concreto: GET /api/users/1
Exemplo concreto: POST /api/products (criação)
Legenda das cores
| Cor | Camada | Principais anotações |
|---|---|---|
| 🔵 Azul | Cliente | Requisição HTTP / Resposta JSON |
| 🔴 Vermelho | Segurança | @EnableWebSecurity, JwtFilter, @PreAuthorize |
| 🟢 Verde | Controller | @RestController, @GetMapping, @PostMapping |
| 🟡 Amarelo | Service | @Service, @Transactional, lógica de negócio |
| 🟠 Laranja | Repository | @Repository, JpaRepository, @Query |
| 🟣 Roxo | Banco de dados | @Entity, @Table, @Id, @Column |
Anotações por Categoria
Spring Boot Annotations
├── Core Spring
│ ├── Estereótipos: @Component, @Service, @Repository, @Controller
│ ├── Configuração: @Configuration, @Bean, @PropertySource
│ ├── Injeção: @Autowired, @Qualifier, @Value, @Inject
│ └── Ciclo de Vida: @PostConstruct, @PreDestroy, @Scope
│
├── Web / REST
│ ├── Controllers: @RestController, @Controller
│ ├── Mapping: @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PatchMapping
│ ├── Parâmetros: @RequestParam, @PathVariable, @RequestBody, @RequestHeader
│ └── Respostas: @ResponseBody, @ResponseStatus, @ExceptionHandler
│
├── Data / JPA
│ ├── Entidades: @Entity, @Table, @Id, @GeneratedValue, @Column
│ ├── Relações: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
│ ├── Consultas: @Query, @NamedQuery, @Modifying
│ └── Transações: @Transactional, @EnableJpaRepositories
│
├── Security
│ ├── Config: @EnableWebSecurity, @EnableMethodSecurity
│ └── Autorização: @PreAuthorize, @PostAuthorize, @Secured
│
├── Teste
│ ├── Boot: @SpringBootTest, @WebMvcTest, @DataJpaTest
│ ├── Mock: @MockBean, @SpyBean
│ └── Config: @TestConfiguration, @ActiveProfiles
│
└── Avançadas
├── Async: @Async, @Scheduled, @EnableScheduling
├── Cache: @Cacheable, @CacheEvict, @EnableCaching
├── Validação: @Valid, @NotNull, @Size, @Email
└── Boot: @SpringBootApplication, @ConditionalOnProperty
Próximo Passo
➡️ Capítulo 1: Anotações Core Spring