All specialtiesTechnology · Job interview

Spring

Spring interviews mix framework theory with everyday decisions. Explain what the framework does for you, and what you would do without it.

Words → phrases → sentences → speaking

Try SpeakRole ↗
Job interviewSpring
V

How does dependency injection work in Spring?

0:18
Interviewer question

Spring

Interviewers for Spring roles want to hear that you understand what happens behind the annotations. Saying that @Autowired "just works" is not enough. Saying how the container creates and connects beans is.

A good structure for spoken answers is: what problem the feature solves, how it works inside the framework, and one pitfall you met in a real project. Pitfalls make an answer sound like experience, not memory.

  • ✓Words → phrases → sentences → speaking
  • ✓Answer meaning
  • ✓Language

Common questions and sample answers

How does dependency injection work in Spring?

What the interviewer wants to hear. The container's role, constructor injection and why it helps testing.

Sample answer to practise aloud

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?

What the interviewer wants to hear. Singleton as the default, and why state inside singletons is dangerous.

Sample answer to practise aloud

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?

What the interviewer wants to hear. The proxy mechanism, the self-invocation problem and the rollback rules.

Sample answer to practise aloud

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?

What the interviewer wants to hear. Conditional configuration and how to override it.

Sample answer to practise aloud

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?

What the interviewer wants to hear. Central handling and a consistent error format.

Sample answer to practise aloud

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.

How to say the key terms

bean
been
annotation
an-uh-TAY-shun
dependency
dih-PEN-den-see
injection
in-JEK-shun
proxy
PROK-see
singleton
SING-gul-ton

Useful phrases for answering

  • Under the hood, Spring creates a proxy that…
  • 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.
  • That depends on whether…
  • I would check the documentation for the exact rule, but the idea is…

Common mistakes to avoid

  • Only listing annotations. Explain what each one makes the framework do.
  • Calling Spring "magic". It sounds as if you do not understand it. Use words like "container" and "proxy" to describe what happens.
  • Not mentioning testing. Interviewers like to hear how a design choice affects unit and integration tests.
  • Mixing up Spring and Spring Boot. Spring is the framework; Spring Boot adds auto-configuration, starters and an embedded server.

Frequently asked questions

Should I study Spring or Spring Boot?

Both, in this order: the core ideas of Spring (container, beans, proxies), then what Spring Boot adds on top. Interviewers often ask about the core ideas using Boot examples.

Do I need to know Spring Security?

For backend roles at most companies, yes at a basic level: authentication versus authorisation, the filter chain, and how you protect an endpoint. Say honestly what you have used.

How should I describe my Spring experience?

Name the version, the modules you used (Web, Data, Security) and one problem you solved. A concrete problem is more convincing than a list of annotations.

Reading an answer is not the same as saying it. Practise each question out loud, then compare the meaning and the language of your own answer.

Try SpeakRole ↗

Other topics in this area