Spring Framework MCQ Test
20 random Spring Framework MCQs with answers: IoC and dependency injection, beans, scopes, configuration, AOP, Spring MVC and transactions.
- 20 random questions
- 20 minutes
- 27 in the question bank
No sign-up needed. Answers and explanations are shown at the end.
About this test
Spring Core concepts come up in every Java backend interview: what the IoC container does, how dependency injection works, bean scopes and lifecycle, AOP and @Transactional.
These are the ideas Spring Boot builds on, so this test is the best warm-up for the Spring Boot one.
Each attempt picks new questions at random from the question bank. You can go back and change answers until you finish or the timer runs out. At the end you see your score, the right answer and a short explanation for every question, and the lessons to revise for the ones you missed.
Sample questions with answers
1. What does IoC (Inversion of Control) mean in Spring?
- Classes create their own dependencies
- The container, not your code, creates and wires objects
- Code runs in reverse
Show answer
B. The container, not your code, creates and wires objects — You declare what you need; Spring supplies it.
2. Which injection style is recommended?
- Constructor injection
- Field injection with @Autowired
- Static injection
Show answer
A. Constructor injection — It allows final fields and easy testing.
3. When do you use @Bean instead of @Component?
- Never
- For classes you can't annotate, like library classes, or custom creation
- For controllers only
Show answer
B. For classes you can't annotate, like library classes, or custom creation — @Bean methods live in @Configuration classes.
4. Default bean scope?
- request
- prototype
- singleton
Show answer
C. singleton — One instance per container.
5. Which beats application.properties?
- Defaults in @Value
- Environment variables
- Nothing
Show answer
B. Environment variables — Command line > env vars > profile files > application.properties.
6. How does Spring apply aspects?
- By copying code
- By editing bytecode at compile time only
- By wrapping beans in proxies
Show answer
C. By wrapping beans in proxies — Calls through the proxy get the advice.
7. By default @Transactional rolls back on…
- Checked exceptions only
- Unchecked exceptions (RuntimeException, Error)
- Every exception
Show answer
B. Unchecked exceptions (RuntimeException, Error) — Use rollbackFor = Exception.class for checked ones.
8. What is DispatcherServlet?
- Spring MVC's front controller that routes every request
- A filter
- A database driver
Show answer
A. Spring MVC's front controller that routes every request — HandlerMapping finds the controller method.
9. What does a RowMapper do?
- Opens connections
- Maps one ResultSet row to an object
- Creates tables
Show answer
B. Maps one ResultSet row to an object — JdbcTemplate handles the rest.