- 1. Core Application Annotations:
@SpringBootApplication: Marks the main class of a Spring Boot application, combining@Configuration,@EnableAutoConfiguration, and@ComponentScan.
2. Web Layer (REST) Annotations:@RestController: Combines@Controllerand@ResponseBody, indicating a class handles RESTful requests and its methods return data directly as the response body.@RequestMapping: Maps HTTP requests to handler methods. Can be used at class or method level.@GetMapping,@PostMapping,@PutMapping,@DeleteMapping: Specific HTTP method mapping annotations for cleaner code.@PathVariable: Binds a method parameter to a URI template variable.@RequestParam: Binds a method parameter to a web request parameter.@RequestBody: Binds the HTTP request body to a method parameter.@ResponseBody: Indicates that the return value of a method should be bound to the web response body.
3. Dependency Injection and Configuration:@Autowired: Automatically injects dependencies by type.@Qualifier: Specifies which bean to inject when multiple beans of the same type exist.@Value: Injects values from properties files or environment variables.@Component,@Service,@Repository: Stereotype annotations for marking classes as Spring components, services, or data access objects, respectively, enabling component scanning.@Configuration: Indicates a class provides bean definitions.@Bean: Marks a method as a bean factory method within a@Configurationclass.
4. Data Access and Transactions:@Entity: Marks a class as a JPA entity.@Table,@Column,@Id: JPA annotations for mapping entities to database tables and columns.@Transactional: Manages transactions for methods or classes.
5. Conditional Annotations:@ConditionalOnProperty: Creates a bean only if a specific property is present and/or has a particular value.@ConditionalOnClass: Creates a bean only if a specific class is on the classpath.
6. Testing Annotations:@SpringBootTest: Loads the entire application context for integration tests.@WebMvcTest: Focuses testing on the web layer, mocking other layers.@DataJpaTest: Focuses testing on JPA components.@MockBean: Adds mocks to the Spring application context.
spring annotation ทั้งหมด
Reviewed by Mr.Boonchai
on
พฤศจิกายน 17, 2568
Rating:
ไม่มีความคิดเห็น:
Thank you