انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-009-L05

الوكلاء الديناميكيون

  • الدرس 5 من 6
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

explain how Spring adds behavior around beans.

الموضوعات المخطط لها

  • java.lang.reflect.Proxy creates an object implementing interfaces; each call goes to an InvocationHandler.
  • The handler can add behavior (timing, transactions) and call the real object.
  • Spring uses JDK proxies for interfaces and CGLIB subclass proxies for classes (verify details for your Spring version).
  • Only calls through the proxy are intercepted. A call from one method to another on this bypasses it, so @Transactional self-invocation does not start a transaction.
  • Fix: move the method to another bean, or inject the proxy.
تفاصيل المخطط المبدئي

عرض عملي

java
Svc proxy = (Svc) Proxy.newProxyInstance(loader, new Class<?>[]{Svc.class},
    (p, m, args) -> { log(m); return m.invoke(target, args); });

اختبر فهمك

Why does this.save() skip @Transactional?

أظهر الإجابة

this is the raw object, not the proxy.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.