الوكلاء الديناميكيون
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
explain how Spring adds behavior around beans.
الموضوعات المخطط لها
java.lang.reflect.Proxycreates an object implementing interfaces; each call goes to anInvocationHandler.- 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
thisbypasses it, so@Transactionalself-invocation does not start a transaction. - Fix: move the method to another bean, or inject the proxy.
تفاصيل المخطط المبدئي
عرض عملي
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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.