Skip to content
Preptima

Spring Core interview questions

Dependency injection, bean lifecycle, scopes, proxies, and why an AOP annotation silently does nothing.

6 questions in Java & Spring.

medium4

mediumConceptScenario

Startup fails with NoUniqueBeanDefinitionException after someone adds a second implementation. Do you reach for @Primary, @Qualifier or a list of beans, and which fix ages badly?

NoUniqueBeanDefinitionException means one injection point matches two beans by type. Fix it where the decision belongs: a qualifier at the consumer when callers need different beans, a List or Map when all are used, a conditional bean when only one should exist. A primary bean is the quick fix that ages worst.

4 minmid, senior
mediumConceptScenario

Why does @Transactional sometimes do nothing at all, even though the annotation is right there?

Spring applies @Transactional through a proxy that wraps the bean. Calling the annotated method from another method of the same class goes through `this`, not the proxy, so the advice never runs and no transaction is started. The same silence affects @Cacheable, @Async and @Retryable. It also connects dependency injection to the point an interviewer is testing.

4 minmid, senior

hard2

hardConceptScenario

A method with REQUIRES_NEW was meant to save an audit row even when the main transaction fails. When does it work, and when does it deadlock?

REQUIRES_NEW suspends the caller's transaction and commits the audit on a second connection, so the row survives a later rollback if the call goes through the Spring proxy. It hangs when the audit touches rows the suspended transaction has locked, or when every thread holds one pooled connection and waits for another.

5 minmid, senior, staff