الوحدة 17: المرجع الكامل لـ Annotations Spring Boot
أهداف الوحدة
هذه الوحدة هي مرجع شامل لجميع Annotations Spring Boot التي ستواجهها في التطوير. تغطي:
- Annotations النواة لـ Spring (IoC، DI، التكوين)
- Annotations الويب وREST
- Annotations الاستمرارية (JPA/Hibernate)
- Annotations الأمان، الاختبار وAnnotations المتقدمة
خطة الوحدة
| # | الفصل | المحتوى |
|---|---|---|
| 1 | Annotations نواة Spring | @Component, @Service, @Repository, @Configuration, @Bean, @Autowired, @Value, @Profile, @Scope, @Conditional... |
| 2 | Annotations الويب وREST | @RestController, @RequestMapping, @GetMapping, @PostMapping, @RequestBody, @PathVariable, @ResponseStatus, @CrossOrigin... |
| 3 | Annotations البيانات وJPA | @Entity, @Table, @Id, @GeneratedValue, @Column, @OneToMany, @ManyToOne, @Query, @Transactional, @Modifying... |
| 4 | Annotations الأمان، الاختبار والمتقدمة | @EnableWebSecurity, @PreAuthorize, @SpringBootTest, @MockBean, @Scheduled, @Async, @EnableCaching, @Validated... |
| 5 | قاموس كامل من A-Z | 120+ Annotations مرتبة أبجدياً مع وصفات قصيرة — مرجع سريع |
كيفية استخدام هذه الوحدة
دليل مرجعي
تم تصميم هذه الوحدة كـ قاموس للAnnotations. ليس عليك قراءتها من البداية إلى النهاية. استخدمها كمرجع عندما تواجه Annotation غير معروف أو تبحث عن Annotation مناسب لاحتياجك.
مسار طلب HTTP في Spring Boot
نظرة عامة: من العميل إلى قاعدة البيانات
تدفق مفصل مع Annotations
الهندسة المعمارية الطبقية وAnnotations الخاصة بها
مثال عملي: GET /api/users/1
مثال عملي: POST /api/products (إنشاء)
مفتاح الألوان
| اللون | الطبقة | Annotations الرئيسية |
|---|---|---|
| 🔵 أزرق | العميل | طلب HTTP / استجابة JSON |
| 🔴 أحمر | الأمان | @EnableWebSecurity، JwtFilter، @PreAuthorize |
| 🟢 أخضر | Controller | @RestController, @GetMapping, @PostMapping |
| 🟡 أصفر | Service | @Service, @Transactional، منطق الأعمال |
| 🟠 برتقالي | Repository | @Repository، JpaRepository، @Query |
| 🟣 بنفسجي | قاعدة البيانات | @Entity, @Table, @Id, @Column |
Annotations حسب الفئة
Spring Boot Annotations
├── نواة Spring
│ ├── Stéréotypes: @Component، @Service، @Repository، @Controller
│ ├── التكوين: @Configuration، @Bean، @PropertySource
│ ├── الحقن: @Autowired، @Qualifier، @Value، @Inject
│ └── دورة الحياة: @PostConstruct، @PreDestroy، @Scope
│
├── الويب / REST
│ ├── Controllers: @RestController، @Controller
│ ├── التوجيه: @GetMapping، @PostMapping، @PutMapping، @DeleteMapping، @PatchMapping
│ ├── المعلمات: @RequestParam، @PathVariable، @RequestBody، @RequestHeader
│ └── الاستجابات: @ResponseBody، @ResponseStatus، @ExceptionHandler
│
├── البيانات / JPA
│ ├── الكيانات: @Entity، @Table، @Id، @GeneratedValue، @Column
│ ├── العلاقات: @OneToOne، @OneToMany، @ManyToOne، @ManyToMany
│ ├── الاستعلامات: @Query، @NamedQuery، @Modifying
│ └── المعاملات: @Transactional، @EnableJpaRepositories
│
├── الأمان
│ ├── التكوين: @EnableWebSecurity، @EnableMethodSecurity
│ └── التفويض: @PreAuthorize، @PostAuthorize، @Secured
│
├── الاختبار
│ ├── Boot: @SpringBootTest، @WebMvcTest، @DataJpaTest
│ ├── Mock: @MockBean، @SpyBean
│ └── التكوين: @TestConfiguration، @ActiveProfiles
│
└── المتقدمة
├── Async: @Async، @Scheduled، @EnableScheduling
├── التخزين المؤقت: @Cacheable، @CacheEvict، @EnableCaching
├── التحقق: @Valid، @NotNull، @Size، @Email
└── Boot: @SpringBootApplication، @ConditionalOnProperty
الخطوة التالية
➡️ الفصل 1: Annotations نواة Spring