helalshaban96 / spring-interview-questions-1

🟣 Spring coding interview questions and answers for developers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top 87 Spring interview questions and answers in 2021.

You can check all 87 Spring interview questions here πŸ‘‰ https://devinterview.io/dev/spring-interview-questions


πŸ”Ή 1. What is Spring?

Answer:

Spring is an open source development framework for enterprise Java. The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based (Plain Old Java Object) programming model.

Source: tutorialspoint.com   


πŸ”Ή 2. What is default scope of bean in Spring framework?

Answer:

The default scope of bean is Singleton for Spring framework.

Source: tutorialspoint.com   


πŸ”Ή 3. What do you mean by Bean wiring ?

Answer:

The act of creating associations between application components (beans) within the Spring container is referred to as Bean wiring.

Source: developersbook.com   


πŸ”Ή 4. What is Spring Security?

Answer:

Spring Security is a separate module of the Spring framework that focuses on providing authentication and authorization methods in Java applications. It also takes care of most of the common security vulnerabilities such as CSRF attacks.

To use Spring Security in web applications, you can get started with a simple annotation: @EnableWebSecurity.

Source: developersbook.com   


πŸ”Ή 5. What does a bean definition contain?

Answer:

The bean definition contains the information called configuration metadata which is needed for the container to know the followings βˆ’

  • How to create a bean
  • Bean's lifecycle details
  • Bean's dependencies
Source: tutorialspoint.com   


πŸ”Ή 6. What is Spring Boot?

Answer:

Spring Boot is a project that provides a pre-configured set of frameworks to reduce boilerplate configuration so that you can have a Spring application up and running with the smallest amount of code.

Source: developersbook.com   


πŸ”Ή 7. What is the DispatcherServlet and what is it used for?

Answer:

The DispatcherServlet is an implementation of the Front Controller design pattern that handles all incoming web request to a Spring MVC application. A Front Controller pattern (see Enterprise application design pattern) is a common pattern in web applications whose job is to receive all request and route it to different components of the application for actual processing.

In Spring MVC, DispatcherServlet is used for finding the correct Controller to process a request, which it does with the help of handler mapping, e.g. the @RequestMapping annotation.

Source: stackoverflow.com   


πŸ”Ή 8. Do you need spring-mvc.jar in your classpath or is it part of spring-core?

Answer:

The spring-mvc.jar is not part of spring-core, which means that if you want to use Spring MVC framework in your Java project, you must include spring-mvc.jar in your application's classpath. In a Java web application, spring-mvc.jar is usually placed inside the /WEB-INF/lib folder.

Source: stackoverflow.com   


πŸ”Ή 9. What are benefits of using Spring?

Answer:

Following is the list of few of the great benefits of using Spring Framework:

  • Lightweight βˆ’ Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.
  • Inversion of control (IOC) βˆ’ Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
  • Aspect oriented (AOP) βˆ’ Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
  • Container βˆ’ Spring contains and manages the life cycle and configuration of application objects.
  • MVC Framework βˆ’ Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over-engineered or less popular web frameworks.
  • Transaction Management βˆ’ Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example).
  • Exception Handling βˆ’ Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.
Source: tutorialspoint.com   


πŸ”Ή 10. What in the world are Spring beans?

Answer:

Spring beans are just object instances that are managed by the Spring container, namely, they are created and wired by the framework and put into a "bag of objects" (the container) from where you can get them later.

The "wiring" part there is what dependency injection is all about, what it means is that you can just say "I will need this thing" and the framework will follow some rules to get you the proper instance.

Source: stackoverflow.com   


πŸ”Ή 11. What is the purpose of the Core Container module?

Answer:

The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.

Source: developersbook.com   


πŸ”Ή 12. What is Application Context?

Answer:

On the surface, an application context is the same as a bean factory. Both load bean definitions, wire beans together, and dispense beans upon request. But it also provides:

  • A means for resolving text messages, including support for internationalization
  • A generic way to load file resources
  • Events to beans that are registered as listeners
Source: developersbook.com   


πŸ”Ή 13. How to integrate Java Server Faces (JSF) with Spring?

Answer:

JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways:

  • DelegatingVariableResolver: Spring comes with a JSF variable resolver that lets you use JSF and Spring together. The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans.

  • FacesContextUtils: custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter.
ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
Source: developersbook.com   


πŸ”Ή 14. What is Spring MVC framework?

Answer:

The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

Source: tutorialspoint.com   


πŸ”Ή 15. How is event handling done in Spring?

Answer:

Event handling in the ApplicationContext is provided through the ApplicationEvent class and ApplicationListener interface. So if a bean implements the ApplicationListener, then every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified.

Source: tutorialspoint.com   


πŸ”Ή 16. What are ORM's Spring supports?

Answer:

Spring supports the following ORM's:

  • Hibernate
  • iBatis
  • JPA (Java Persistence API)
  • TopLink
  • JDO (Java Data Objects)
  • OJB
Source: tutorialspoint.com   


πŸ”Ή 17. What are the different modules in Spring framework?

Answer:

Following are the modules of the Spring framework:

  • Core module
  • Bean module
  • Context module
  • Expression Language module
  • JDBC module
  • ORM module
  • OXM module
  • Java Messaging Service(JMS) module
  • Transaction module
  • Web module
  • Web-Servlet module
  • Web-Struts module
  • Web-Portlet module
Source: tutorialspoint.com   


πŸ”Ή 18. Explain the @Controller annotation.

Answer:

The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API.

Source: tutorialspoint.com   


πŸ”Ή 19. How do you provide configuration metadata to the Spring Container?

Answer:

There are following three important methods to provide configuration metadata to the Spring Container βˆ’

  • XML based configuration file.
  • Annotation-based configuration
  • Java-based configuration
Source: tutorialspoint.com   


πŸ”Ή 20. What are Spring beans?

Answer:

The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.

Source: tutorialspoint.com   


πŸ”Ή 21. Explain @RequestMapping annotation.

Answer:

@RequestMapping annotation is used to map a URL to either an entire class or a particular handler method.

Source: tutorialspoint.com   


πŸ”Ή 22. How does the scope Prototype work?**

Answer:

Scope prototype means that every time you call for an instance of the Bean, Spring will create a new instance and return it. This differs from the default singleton scope, where a single object instance is instantiated once per Spring IoC container.

Source: developersbook.com   


πŸ”Ή 23. What is the Model?

Answer:

Model is a reference to encapsulate the data or output for rendering. Model is always created and passed to the view in Spring MVC. If a mapped controller method has Model as a method parameter, then a model instance is automatically injected by Spring framework to that method.

Source: dzone.com   


πŸ”Ή 24. What is a View and what's the idea behind supporting different types of View?

Answer:

A View is an interface in Spring MVC application whose implementations are responsible for rendering context and exposing the model. A single view exposes multiple model attributes. Views in Spring MVC can be beans.

They are likely to be instantiated as beans by a ViewResolver. As this interface is stateless, view implementations should be thread-safe. By using ViewResolver, a logical name of view can be resolved into different types of View implementation, e.g. JstlView for displaying JSP or other view implementations for FreeMarker and Velocity.

Source: dzone.com   


πŸ”Ή 25. What is Spring JDBCTemplate class and how to use it?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 26. What is the use of WebClient and WebTestClient?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 27. What is the purpose of the session scope?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 28. Explain Bean lifecycle in Spring framework

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 29. Does Spring Bean provide thread safety?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 30. What is Spring IoC Container?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 31. Can we send an Object as the response of Controller handler method?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 32. Is the DispatcherServlet instantiated via an application context?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 33. What is the difference between Bean Factory and Application Context?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 34. What do you mean by Auto Wiring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 35. Explain the difference between spring @Controller and @RestController annotation

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 36. What is Controller in Spring MVC framework?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 37. What are the differences between @RequestParam and @PathVariable?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 38. Describe some of the standard Spring events

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 39. What is Bean Factory?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 40. How can you inject Java Collection in Spring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 41. What is AOP?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 42. What is Spring IoC container?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 43. How is the right View chosen when it comes to the rendering phase?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 44. What is the typical Bean life cycle in Spring Bean Factory Container?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 45. Why are controllers testable artifacts?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 46. How to handle exceptions in Spring MVC Framework?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 47. What is the difference between Bean Factory and ApplicationContext?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 48. Name some of the Design Patterns used in the Spring Framework?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 49. How do you define a bean scope?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 50. How would you relate Spring MVC Framework to MVC architecture?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 51. What are the types of the transaction management Spring supports?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 52. What is Aspect?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 53. How to validate form data in Spring Web MVC Framework?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 54. What is bean auto wiring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 55. What are some benefits of using Spring Transactions?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 56. What is Aspect-Oriented Programming?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 57. What are some of the important Spring annotations you have used?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 58. What are the limitations with autowiring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 59. What are the advantages of Spring MVC over Struts MVC ?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 60. What is reactive programming?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 61. What’s the difference between @Component, @Controller, @Repository & @Service annotations in Spring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 62. How is an incoming request mapped to a controller and mapped to a method?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 63. What bean scopes does Spring support? Explain them.

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 64. What is the default scope in the web context?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 65. What is Spring MVC Interceptor and how to use it?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 66. What are different Modes of auto wiring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 67. What is Join point?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 68. What are inner beans in Spring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 69. What are Aspect, Advice, Pointcut, and JoinPoint in AOP?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 70. What is Weaving?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 71. What are the different types of Advices?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 72. What is the difference between concern and cross-cutting concern in Spring AOP?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 73. What are the disadvantages of using Reactive Streams?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 74. Compare @Component (v2.5) versus @Bean (v 3.0)

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 75. What is Spring WebFlux?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 76. Is Spring 5 compatible with older versions of Java?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 77. How does Spring 5 integrate with JDK 9 modularity?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 78. What are some of the best practices for Spring Framework?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 79. How does autowiring work in Spring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 80. Explain the difference between <context:annotation-config> vs <context:component-scan>

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 81. I want to know what actually happens when you annotate a method with @Transactional?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 82. Where does the @Transactional annotation belong?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 83. What are some of the valid return types of a controller method?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 84. What is the difference between @Inject and @Autowired in Spring Framework? Which one to use under what condition?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 85. What's the difference between @Component, @Repository & @Service annotations in Spring?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 86. Can we use both Web MVC and WebFlux in the same application?

πŸ‘‰πŸΌ Check all 87 answers


πŸ”Ή 87. What are the Mono and Flux types?

πŸ‘‰πŸΌ Check all 87 answers



Thanks πŸ™Œ for reading and good luck on your next tech interview!
Explore 3800+ dev interview question here πŸ‘‰ Devinterview.io

About

🟣 Spring coding interview questions and answers for developers.