• +91 9723535972
  • info@interviewmaterial.com

Spring Interview Questions and Answers

Spring Interview Questions and Answers

Question - 21 : - What Is Spring Security?

Answer - 21 : -

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, we can get started with the simple annotation @EnableWebSecurity.

Question - 22 : - What Is Spring Boot?

Answer - 22 : -

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

Question - 23 : - Name Some of the Design Patterns Used in the Spring Framework?

Answer - 23 : -

  • Singleton Pattern – singleton-scoped beans
  • Factory Pattern – Bean Factory classes
  • Prototype Pattern – prototype-scoped beans
  • Adapter Pattern – Spring Web and Spring MVC
  • Proxy Pattern – Spring Aspect-Oriented Programming support
  • Template Method Pattern – JdbcTemplate, HibernateTemplate, etc.
  • Front Controller – Spring MVC DispatcherServlet
  • Data Access Object – Spring DAO support
  • Model View Controller – Spring MVC

Question - 24 : - How Does the Scope Prototype Work?

Answer - 24 : -

Scope prototype means that every time we 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.

Question - 25 : - How to Enable Transactions in Spring and What Are Their Benefits?

Answer - 25 : -

There are two distinct ways to configure Transactions — with annotations or by using Aspect-Oriented Programming (AOP) — each with their advantages.

Here are the benefits of using Spring Transactions, according to the official docs:

  • Provide a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA and JDO
  • Support declarative transaction management
  • Provide a simpler API for programmatic transaction management than some complex transaction APIs such as JTA
  • Integrate very well with Spring's various data access abstractions

Question - 26 : - What Is Spring DAO?

Answer - 26 : -

Spring Data Access Object (DAO) is Spring's support provided to work with data access technologies like JDBC, Hibernate and JPA in a consistent and easy way.

There is an entire series discussing persistence in Spring that provides a more in-depth look.

Question - 27 : - What Are Aspect, Advice, Pointcut and JoinPoint in AOP?

Answer - 27 : -

Aspect – a class that implements cross-cutting concerns, such as transaction management
Advice – the methods that get executed when a specific JoinPoint with matching Pointcut is reached in the application
Pointcut – a set of regular expressions that are matched with JoinPoint to determine whether Advice needs to be executed or not
JoinPoint – a point during the execution of a program, such as the execution of a method or the handling of an exception

Question - 28 : - What Is Weaving?

Answer - 28 : -

According to the official docs, weaving is a process that links aspects with other application types or objects to create an advised object. This can be done at compile time, load time, or runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.

Question - 29 : - What Is Spring WebFlux?

Answer - 29 : -

Spring WebFlux is Spring's reactive-stack web framework, and it's an alternative to Spring MVC.

In order to achieve this reactive model and be highly scalable, the entire stack is non-blocking. Check out our tutorial on Spring 5 WebFlux for additional details.

Question - 30 : - What Is the Use of WebClient and WebTestClient?

Answer - 30 : -

WebClient is a component in the new Web Reactive framework that can act as a reactive client for performing non-blocking HTTP requests. Since it's reactive client, it can handle reactive streams with back pressure, and it can take full advantage of Java 8 lambdas. It can also handle both sync and async scenarios.

On the other hand, the WebTestClient is a similar class that we can use in tests. Basically, it's a thin shell around the WebClient. It can connect to any server over an HTTP connection. It can also bind directly to WebFlux applications using mock request and response objects, without the need for an HTTP server.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners