كل التخصصاتالتقنية · مقابلة عمل

Spring

تمزج مقابلات Spring بين نظرية الإطار وقرارات العمل اليومي. اشرح ما يفعله الإطار نيابةً عنك، وما كنت ستفعله بدونه.

كلمات → عبارات → جمل → تحدث

جرّب SpeakRole ↗
مقابلة عملSpring
V

How does dependency injection work in Spring?

0:18
سؤال المقابل

Spring

يريد المحاورون في وظائف Spring أن يسمعوا أنك تفهم ما يحدث خلف التعليقات التوضيحية (annotations). قول إن @Autowired «يعمل وحسب» لا يكفي، أما شرح كيف تنشئ الحاوية (container) الـ beans وتربط بينها فهو المطلوب.

بنية جيدة للإجابات الشفهية: ما المشكلة التي تحلّها الميزة، وكيف تعمل داخل الإطار، وعقبة واحدة واجهتها في مشروع حقيقي. العقبات تجعل الإجابة تبدو كأنها خبرة لا حفظ.

  • ✓كلمات → عبارات → جمل → تحدث
  • ✓معنى الإجابة
  • ✓اللغة

أكثر الأسئلة تكرارًا ونماذج الإجابات

How does dependency injection work in Spring?

كيف يعمل حقن الاعتماديات (dependency injection) في Spring؟

ما الذي يريد المحاور سماعه. دور الحاوية (container)، والحقن عبر المُنشئ (constructor)، ولماذا يساعد ذلك على الاختبار.

نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍ

In Spring, I do not create my dependencies with new. I declare what a class needs, usually in the constructor, and the container creates the objects, which we call beans, and passes them in. At startup Spring scans the classes, builds a graph of beans and connects them. I prefer constructor injection, because dependencies are explicit and can be final, and in a unit test I can pass a mock directly without starting Spring. Field injection hides dependencies and makes classes harder to test.

What are bean scopes in Spring?

ما نطاقات الـ bean (bean scopes) في Spring؟

ما الذي يريد المحاور سماعه. Singleton هو النطاق الافتراضي، ولماذا تكون الحالة داخل الـ singleton خطرة.

نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍ

The default scope is singleton: Spring creates one instance per application context and shares it. Prototype creates a new instance every time the bean is requested. In web applications there are also request and session scopes. The most important thing to remember is that singleton beans are shared between threads, so they must not keep mutable request-specific state in fields. If I need per-request data, I pass it as method arguments or use a request-scoped bean.

How does @Transactional work, and what are its pitfalls?

كيف تعمل @Transactional وما عقباتها؟

ما الذي يريد المحاور سماعه. آلية الـ proxy، ومشكلة الاستدعاء الذاتي (self-invocation)، وقواعد التراجع (rollback).

نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍ

Spring wraps the bean in a proxy. When a method with @Transactional is called from outside, the proxy opens a transaction, calls the real method, and commits or rolls back. One pitfall is self-invocation: if a method calls another transactional method in the same class, the call does not go through the proxy, so the annotation is ignored. Another is that by default Spring rolls back only on unchecked exceptions, not on checked ones, unless I set rollbackFor. I also keep transactions short and avoid remote calls inside them.

What does Spring Boot auto-configuration do?

ماذا يفعل الإعداد التلقائي (auto-configuration) في Spring Boot؟

ما الذي يريد المحاور سماعه. الإعداد المشروط وكيفية تجاوز الإعدادات الافتراضية.

نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍ

Spring Boot looks at the libraries on the classpath and the properties I set, and configures sensible defaults for me. For example, if it sees a database driver and a connection URL, it creates a DataSource. Each auto-configuration class is guarded by conditions, like "only if this class is present" or "only if I did not define my own bean". That last condition is important, because it means I can always override the default by defining my own bean. When something behaves strangely, I enable the conditions report to see what was applied and why.

How do you handle exceptions in a Spring REST API?

كيف تعالج الاستثناءات في REST API مبنية على Spring؟

ما الذي يريد المحاور سماعه. معالجة مركزية للاستثناءات وصيغة ثابتة وموحدة للأخطاء.

نموذج إجابة بالإنجليزية للتدرّب عليه بصوت عالٍ

I use a class with @RestControllerAdvice and methods annotated with @ExceptionHandler. This way controllers stay clean, and every error is converted to the same JSON format: a status code, a short error code and a message that is safe to show. I map business exceptions to the right HTTP status, for example 404 for a missing resource and 409 for a conflict. I never return stack traces to clients. I log the details with a correlation ID, so support can find the full error in the logs.

كيف تنطق المصطلحات الأساسية

bean
بِين
annotation
أَنَتَيْشِن
dependency
دِبِنْدِنْسِي
injection
إِنْجِكْشِن
proxy
بْرُوكْسِي
singleton
سِنْغِلْتُن

عبارات مفيدة للإجابة

  • Under the hood, Spring creates a proxy that…خلف الكواليس، ينشئ Spring وكيلًا (proxy) يقوم بـ…
  • The default behaviour is…, but I can change it by…السلوك الافتراضي هو…، لكن يمكنني تغييره عن طريق…
  • One pitfall I ran into was…من العقبات التي واجهتها…
  • In a unit test, I would replace this with a mock.في اختبار الوحدة (unit test) كنت سأستبدل هذا بكائن محاكاة (mock).
  • That depends on whether…هذا يعتمد على ما إذا كان…
  • I would check the documentation for the exact rule, but the idea is…كنت سأراجع الوثائق لمعرفة القاعدة الدقيقة، لكن الفكرة هي…

أخطاء شائعة

  • الاكتفاء بسرد التعليقات التوضيحية. اشرح ما يجعله كل منها الإطار يفعله.
  • وصف Spring بأنه «سحر». هذا يوحي بأنك لا تفهمه. استخدم كلمات مثل «الحاوية» و«الوكيل (proxy)» لوصف ما يحدث.
  • عدم ذكر الاختبار. يحب المحاورون أن يسمعوا كيف يؤثر قرار التصميم في اختبارات الوحدة واختبارات التكامل.
  • الخلط بين Spring وSpring Boot. Spring هو الإطار، أما Spring Boot فيضيف الإعداد التلقائي وحزم البدء (starters) وخادمًا مدمجًا.

الأسئلة الشائعة

هل أدرس Spring أم Spring Boot؟

الاثنين بهذا الترتيب: أولًا الأفكار الأساسية في Spring (الحاوية، والـ beans، والـ proxies)، ثم ما يضيفه Spring Boot فوقها. وكثيرًا ما يسأل المحاورون عن الأفكار الأساسية بأمثلة من Boot.

هل أحتاج إلى معرفة Spring Security؟

في وظائف الـ backend في معظم الشركات نعم، على مستوى أساسي: المصادقة (authentication) مقابل التفويض (authorization)، وسلسلة المرشِّحات (filter chain)، وكيف تحمي نقطة نهاية (endpoint). قل بصدق ما استخدمته.

كيف أصف خبرتي مع Spring؟

اذكر الإصدار والوحدات التي استخدمتها (Web وData وSecurity) ومشكلة واحدة حللتها. المشكلة المحددة أكثر إقناعًا من قائمة بالتعليقات التوضيحية.

قراءة الإجابة ليست مثل قولها. تدرّب على كل سؤال بصوت عالٍ، ثم قارن معنى إجابتك ولغتها بالنموذج.

جرّب SpeakRole ↗

موضوعات أخرى في هذا المجال