Prev Next

Spring / Spring7 basics Interview questions

1. What is Spring Framework 7? 2. What is the minimum Java version required by Spring Framework 7? 3. What is Jakarta EE 11 support in Spring Framework 7? 4. What is Inversion of Control in Spring? 5. What is Dependency Injection in Spring? 6. What are the types of Dependency Injection in Spring? 7. What is an ApplicationContext? 8. What is a BeanFactory in Spring? 9. What are Spring beans? 10. What are the types of bean scopes in Spring? 11. What is the purpose of the @Component annotation? 12. What is the purpose of the @Autowired annotation? 13. What is the purpose of the @Configuration annotation? 14. What is the purpose of the @Bean annotation? 15. What are stereotype annotations in Spring? 16. What is component scanning in Spring? 17. What is the BeanRegistrar contract introduced in Spring Framework 7? 18. What is JSpecify in Spring Framework 7? 19. What is the purpose of the @Value annotation? 20. What are Spring profiles? 21. Define a Spring Boot starter? 22. What is auto-configuration in Spring Boot 4? 23. What is the DispatcherServlet in Spring MVC? 24. What is a RestController in Spring MVC? 25. What is API Versioning support in Spring Framework 7? 26. What are the types of HTTP message converters in Spring? 27. Describe the RestClient in Spring Framework 7? 28. What is the purpose of HTTP Interface clients in Spring? 29. What are the types of Spring AOP advice? 30. Define an Aspect in Spring AOP? 31. What is the purpose of the @Transactional annotation? 32. What are the types of transaction propagation in Spring? 33. Describe AOT processing in Spring Framework 7? 34. What is GraalVM native image support in Spring Framework 7? 35. What is virtual thread support in Spring Framework 7? 36. What is the purpose of a PropertySource in Spring? 37. List the core modules of Spring Framework 7? 38. Define a Spring MVC ViewResolver? 39. What is the purpose of ResponseEntity? 40. Describe the Spring Bean lifecycle basics?

1. What is Spring Framework 7?

Spring Framework 7 is the current major generation of the Spring Framework, reaching general availability on November 13, 2025 alongside Spring Boot 4 . It keeps Java 17 as its minimum baseline while fully supporting Java 25, the latest LTS release, so teams can use records, sealed classes, and p...

Read full answer

2. What is the minimum Java version required by Spring Framework 7?

Spring Framework 7 keeps Java 17 as its minimum supported version, the same baseline Spring 6 introduced back in 2022. This was a deliberate, pragmatic choice: rather than forcing every team onto the newest JDK the moment a major Spring version ships, the framework lets you stay on a widely adopt...

Read full answer

3. What is Jakarta EE 11 support in Spring Framework 7?

Spring Framework 7 migrates its enterprise APIs from Jakarta EE 10 to Jakarta EE 11 . In practice this raises the baseline to Servlet 6.1 , WebSocket 2.2 , Bean Validation 3.1 , and JPA 3.2 , replacing the older generations that Spring 6 relied on. Because these specifications moved forward, the ...

Read full answer

4. What is Inversion of Control in Spring?

Inversion of Control (IoC) is the design principle where an object no longer creates or looks up its own collaborators; instead, control over object creation and wiring is handed to a container. In a plain Java program, a class typically instantiates the objects it depends on with new . Under IoC...

Read full answer

5. What is Dependency Injection in Spring?

Dependency Injection (DI) is the specific technique Spring uses to implement IoC: rather than a bean looking up or constructing the objects it needs, the container "injects" those dependencies into it, usually through a constructor, a setter, or a field. For example, an OrderService that needs a ...

Read full answer

6. What are the types of Dependency Injection in Spring?

Spring supports three main styles of injecting dependencies into a bean, and picking the right one affects testability and immutability. Type How it works Constructor injection Dependencies passed as constructor arguments; recommended default, supports immutable, non-null fields Setter injection ...

Read full answer

7. What is an ApplicationContext?

An ApplicationContext is Spring's central interface for the IoC container - it extends BeanFactory and adds enterprise features on top of basic bean wiring. It reads bean definitions (from annotations, Java @Configuration classes, or XML), creates and wires the beans, and manages their full lifec...

Read full answer

8. What is a BeanFactory in Spring?

BeanFactory is the root interface of Spring's IoC container - it defines the core contract for holding bean definitions and producing bean instances on request, including support for dependency injection, bean scopes, and lifecycle callbacks. It is intentionally minimal and lightweight compared t...

Read full answer

9. What are Spring beans?

A Spring bean is simply an object whose creation, configuration, and lifecycle are managed by the Spring IoC container instead of being managed manually by application code. Any plain Java object can become a bean once it's registered with the container, whether through a stereotype annotation li...

Read full answer

10. What are the types of bean scopes in Spring?

Bean scope defines how many instances of a bean the container creates and how long each one lives. Scope Lifetime singleton One shared instance per container (the default) prototype A new instance every time the bean is requested request One instance per HTTP request (web-aware contexts) session ...

Read full answer

11. What is the purpose of the @Component annotation?

@Component marks a plain Java class as a candidate for auto-detection during component scanning , so Spring registers it as a bean without any explicit @Bean method or XML entry. It's the most generic stereotype annotation in the framework. @Component public class SlugGenerator { public String sl...

Read full answer

12. What is the purpose of the @Autowired annotation?

@Autowired tells the Spring container to automatically resolve and inject a matching bean into a constructor, setter, or field. Spring first tries to match by type; if more than one bean of that type exists, it falls back to matching by the parameter or field name, or you can disambiguate with @Q...

Read full answer

13. What is the purpose of the @Configuration annotation?

@Configuration marks a class as a source of bean definitions written in plain Java rather than XML. Spring processes the class specially so that any @Bean methods inside it are only ever invoked once per container, even if one @Bean method calls another directly - the container intercepts the cal...

Read full answer

14. What is the purpose of the @Bean annotation?

@Bean is applied to a method inside a @Configuration (or @Component ) class to tell Spring that the method's return value should be registered and managed as a bean. It's typically used when you need to wire a third-party class you don't own, or when bean creation needs custom logic that a simple...

Read full answer

15. What are stereotype annotations in Spring?

Stereotype annotations are specialized forms of @Component that both register a class as a bean and communicate its architectural role to Spring and to other developers reading the code. Annotation Role @Service Business/service-layer logic @Repository Data-access layer; enables automatic persist...

Read full answer

16. What is component scanning in Spring?

Component scanning is the process where Spring walks a specified package (and its sub-packages) at startup, looking for classes annotated with @Component or one of its stereotypes, and automatically registers each one as a bean - no manual @Bean method needed for every class. @SpringBootApplicati...

Read full answer

17. What is the BeanRegistrar contract introduced in Spring Framework 7?

BeanRegistrar is a new programmatic bean-registration contract added in Spring Framework 7 that gives developers a cleaner, code-first alternative to cramming complex registration logic into @Bean methods. Spring's own guidance discourages registering several beans from a single @Bean method or r...

Read full answer

18. What is JSpecify in Spring Framework 7?

JSpecify is a community-standard set of nullability annotations (like @Nullable and @NonNull ) that Spring Framework 7 has adopted in place of its own previous nullability annotations. The goal is a single, tool-agnostic way to declare which parameters, fields, and return types can be null. impor...

Read full answer

19. What is the purpose of the @Value annotation?

@Value injects a single value - typically read from application properties, environment variables, or a PropertySource - directly into a field, constructor parameter, or setter, using ${...} placeholder syntax. It also supports Spring Expression Language (SpEL) for simple computed defaults. @Comp...

Read full answer

20. What are Spring profiles?

Profiles let you group beans and configuration so that only a chosen subset is active for a given environment - typically dev , test , and prod . A bean marked with @Profile("dev") is only registered when the dev profile is active; it's completely invisible to the container otherwise. @Bean @Prof...

Read full answer

21. Define a Spring Boot starter?

A Spring Boot starter is a curated dependency descriptor - just a Maven or Gradle artifact with no code of its own - that pulls in a coherent set of libraries known to work well together for a particular purpose, so you don't have to hand-pick and version-match each one yourself.

Read full answer

22. What is auto-configuration in Spring Boot 4?

Auto-configuration is Spring Boot's mechanism for guessing and applying sensible default configuration based on what's found on the classpath and in the ApplicationContext , so you don't have to wire common beans by hand. If Boot detects an embedded database driver and no DataSource bean, for ins...

Read full answer

23. What is the DispatcherServlet in Spring MVC?

DispatcherServlet is the single front controller that every incoming HTTP request in a Spring MVC application passes through first. It doesn't contain business logic itself; instead it coordinates the whole request-handling pipeline - consulting handler mappings, invoking interceptors, calling yo...

Read full answer

24. What is a RestController in Spring MVC?

@RestController is a convenience annotation combining @Controller and @ResponseBody , meaning every handler method's return value is written directly to the HTTP response body - typically serialized to JSON by Jackson - instead of being resolved to a view template. @RestController @RequestMapping...

Read full answer

25. What is API Versioning support in Spring Framework 7?

Spring Framework 7 adds native, declarative API versioning through a new version attribute on @RequestMapping and its shortcuts like @GetMapping , removing the need for the URL-prefix or custom-header hacks teams used before. @RestController @RequestMapping ( "/products" ) public class ProductCon...

Read full answer

26. What are the types of HTTP message converters in Spring?

HttpMessageConverter implementations translate between Java objects and HTTP request/response bodies, choosing a converter based on content type and target Java type. Converter Handles MappingJackson2HttpMessageConverter JSON via Jackson StringHttpMessageConverter Plain text bodies FormHttpMessag...

Read full answer

27. Describe the RestClient in Spring Framework 7?

RestClient is Spring's modern, fluent HTTP client for synchronous calls, offering a chainable API that's more concise than the older RestTemplate while staying blocking and easy to reason about (unlike the reactive WebClient ). RestClient client = RestClient.create("https://api.example.com"); Pro...

Read full answer

28. What is the purpose of HTTP Interface clients in Spring?

HTTP Interface clients let you declare a remote service as a plain Java interface annotated with @HttpExchange (and its @GetExchange , @PostExchange shortcuts), and Spring generates a working proxy implementation at runtime - no boilerplate client code to write by hand. @HttpExchange ( "/accounts...

Read full answer

29. What are the types of Spring AOP advice?

Advice is the action Spring AOP takes at a matched join point. Spring supports five advice types, each firing at a different moment relative to the method call. Advice Fires @Before Before the method executes @AfterReturning After the method returns successfully @AfterThrowing After the method th...

Read full answer

30. Define an Aspect in Spring AOP?

An Aspect is a module that captures a cross-cutting concern - logic like logging, security checks, or transaction handling that would otherwise be scattered across many unrelated classes - and applies it declaratively at defined points in the program, called join points. @Aspect @Component public...

Read full answer

31. What is the purpose of the @Transactional annotation?

@Transactional wraps a method (or every public method in a class) in a database transaction managed by Spring, automatically committing on success and rolling back on an unchecked exception, without you writing any manual begin/commit/rollback calls. @Service public class TransferService { @Trans...

Read full answer

32. What are the types of transaction propagation in Spring?

Propagation defines how a @Transactional method behaves when it's called while a transaction is already in progress. Propagation Behavior REQUIRED (default) Joins the existing transaction, or starts a new one if none exists REQUIRES_NEW Always suspends any existing transaction and starts a fresh ...

Read full answer

33. Describe AOT processing in Spring Framework 7?

Ahead-of-Time (AOT) processing shifts work that Spring normally does at runtime - resolving conditions, computing bean definitions, generating proxy classes - to build time instead. During the build, Spring analyzes the application context and generates Java source and bytecode that reproduce tha...

Read full answer

34. What is GraalVM native image support in Spring Framework 7?

GraalVM native image support lets a Spring Framework 7 application be compiled ahead of time into a standalone native executable, rather than running as bytecode inside a JVM. The result starts in milliseconds and uses a fraction of the memory of a regular JVM process, which is valuable for serve...

Read full answer

35. What is virtual thread support in Spring Framework 7?

Virtual threads , a JVM feature from Project Loom, are lightweight threads that the JVM schedules onto a small pool of OS threads, letting an application handle enormous numbers of concurrent blocking calls without the memory overhead of one OS thread per request. Spring Framework 7 lets a tradit...

Read full answer

36. What is the purpose of a PropertySource in Spring?

A PropertySource represents a single origin of key-value configuration - a .properties file, a .yml file, environment variables, or command-line arguments - that Spring's Environment abstraction merges together into one searchable set of properties. @Configuration @PropertySource ( "classpath:mai...

Read full answer

37. List the core modules of Spring Framework 7?

Spring Framework 7 is organized into a set of well-defined modules, and applications typically pull in only the ones they need. spring-core / spring-beans - the IoC container and dependency injection fundamentals spring-context - ApplicationContext, events, internationalization spring-aop - aspec...

Read full answer

38. Define a Spring MVC ViewResolver?

A ViewResolver maps the logical view name a controller returns (like "productList") to an actual renderable View object, such as a JSP, Thymeleaf template, or another template engine's output. It's only invoked for traditional server-rendered controllers, not @RestController endpoints. @Controlle...

Read full answer

39. What is the purpose of ResponseEntity?

ResponseEntity represents a complete HTTP response - status code, headers, and body - giving a controller method full control over what's sent back, rather than just returning a body and letting Spring pick a default 200 OK status. @GetMapping ( "/{id}" ) public ResponseEntity < Product > getP...

Read full answer

40. Describe the Spring Bean lifecycle basics?

Every Spring bean moves through a predictable sequence of stages between creation and destruction, and the container exposes hook points at several of them for custom logic. flowchart TD A[Instantiate bean] --> B[Populate properties / inject dependencies] B --> C[BeanNameAware, BeanFactoryAware c...

Read full answer

«
»

Comments & Discussions