Home » Spring

Spring

Last Updated on July 9, 2023 by KnownSense

31. What is Advice in Spring and explain its types?
Any action taken by an aspect at some particular joinpoint in Spring Framework is called an Advice. Spring AOP makes use of advice for maintaining a chain of interceptors “around” the joinpoint i.e. as an interceptor. Advice can be of the following types:

  • After (finally) – Configured using the @After annotation mark, it is executed after a joinpoint method, whether exiting normally or throwing an exception
  • After returning – Configured using the @AfterReturning annotation mark, it is executed right after the joinpoint method completes normal execution
  • After throwing – Configured using the @AfterThrowing annotation mark, it is executed if and only if the jointpoint method exits by throwing an exception
  • Around – Configured using the @Around annotation mark, it is executed before as well as after a joinpoint method
  • Before – Configured using the @Before annotation mark, it is executed before the joinpoint method

32. What is Spring MVC?
The Spring MVC framework is responsible for providing model-view-controller architecture as well as ready-to-use components, used for developing flexible and loosely coupled web apps.
The MVC pattern helps in separating out the various aspects of the application, such as business logic, input logic, and UI logic, in addition to providing a loose coupling amongst these separated elements.

33. What is a Dispatcher Servlet?
The DispatcherServlet is the essence of Spring Web MVC framework and handles all the HTTP requests as well as responses. Upon receiving the entry of handler mapping from the configuration file, the DispatcherServlet forwards the request to the controller.
Thereafter, the controller returns an object of Model and View. Afterward, the Dispatcher Servlet checks the configuration file for the entry of view resolver and calls the specified view component.

34. What is proxy in Spring?
A proxy in the Spring framework is referred to as the creation of an object after applying advice to a particular target object. 

35. What is Spring Security?
Spring Security is a separate module in the Spring framework that focuses on offering authentication and authorization methods that can be used in Java Applications.

36. What is Reactive programming?
Reactive programming is a non-blocking and event-driven application. It scales with a small number of threads. The backpressure is on the key ingredient, which ascertains that the producers do not overwhelm consumers.

37. Does Spring bean provides thread-safety?
The default scope of Spring bean is singleton, so there will be only one instance per context. That means that all the having a class level variable that any thread can update will lead to inconsistent data. Hence in default mode spring beans are not thread-safe.
However, we can change spring bean scope to request, prototype or session to achieve thread-safety at the cost of performance. It’s a design decision and based on the project requirements.

38. What is Dispatcher servlet and ContextLoad listener?
DispatcherServlet is the front controller in the Spring MVC application and it loads the spring bean configuration file and initializes all the beans that are configured. If annotations are enabled, it also scans the packages and configures any bean annotated with @Component@Controller@Repository, or @Service annotations.
ContextLoaderListener is the listener to start up and shut down Spring’s root WebApplicationContext. Its important functions are to tie up the lifecycle of ApplicationContext to the lifecycle of the ServletContext and to automate the creation of ApplicationContext. We can use it to define shared beans that can be used across different spring contexts.

39. Define Mono and Flux types?
Mono and Flux types, are both the reactor of the Spring Framework 5. The Mono represents the single async value, while the Flux represents the stream of async value. Together they help to implement the publisher interface, which is defined clearly in the reactive streams specifications.

40. What are common features of mono and flux?
The common features of Mono and Flux include the following.

  • They represent streams.
  • They can’t be executed without consuming the stream using the subscribe method.
  • They are immutable and can be called again and again to create a new instance of Flux or Mono.


Authored by codingknownsense.com

Scroll to Top