Mar

Spring Interview Questions
- Nikita Singh
- 14th Mar, 2022
- 381 Followers
Spring Interview Questions
Spring is an open source development framework for enterprise Java. The main features of spring may be used for developing applications of Java. Also, extensions for making web applications on top of JavaEE platform can be done. The main goal of spring is to make the development of J2EE development a lot easier to use and promote a programming practice by making use of POJO-based models. Spring is a lightweight framework. It can also be termed as the framework of frameworks because it also provides to other frameworks like EJB, JSF, Tapestry, Hibernate etc. This framework is defined as a structure using which we can find the solutions to various technical problems. It comprises many modules like ORM, DAO, AOP, WEB MVC etc.
Read Best Spring Interview Questions for Experienced Professionals
We hereby provide you with some questions on spring. These Spring Interview Questions have been specially designed so that it will help you to understand the nature of questions you may encounter while you are in an interview and the subject is spring.
In many interviews, interviewers start questioning the basic concept and then ask questions based on how you answer the basic ones.
Spring Interview Questions
1) What are the features/ characteristics of spring?
- Lightweight: Considering transparency and size, spring is lightweight. The basic versions of spring are below 2MB in size. Also, the overhead processing is also quite negligible.
- Inversion of control (IOC): The objects in spring provide their dependencies instead of creating dependent objects. This is known as Inversion of Control.
- Aspect-oriented Programming (AOP): Aspect-oriented programming or AOP in spring supports cohesive development. Separating application and business logic from system services does this.
- Container: Spring creates as well as manages the life cycle and configures the application objects.
- MVC Framework: Spring’s MVC application framework can be configured easily with the help of strategy interfaces, and it also accommodates multiple view technologies like JSP, POI, and iText. Therefore different frameworks can be used instead of Spring Framework (MVC).
- Transaction Management: Spring comes with Generic abstraction layer for transaction management. This allows us to add the many transaction managers, which make it easy to making transactions without thinking much about low-level issues.
- JDBC Exception Handling: The abstraction layer JDBC of Spring provides an exception hierarchy, which makes the error handling strategy simple.
2) How many types of modules are there in spring? Name them.
The modules are:
- Core module
- Bean module
- SpEL module
- Context module
- JDBC (Java DataBase Connectivity)
- ORM (Object Relational Mapping)
- OXM (Object XML Mappers)
- JMS (Java Messaging Service)
- Transaction
- Web
- Web MVC
- Web Socket
- Web Portlet
- Aspect Oriented Programming (AOP)
- Instrumentation
- Test
- Messaging
- Aspects
3) What do you mean by Spring Java Based Configuration?
For example, Java Annotation @Configuration is used to indicate that Spring IoC container can use the class, which is a source of bean definitions.
4) What are the advantages of spring?
- Spring provides for templates for JDBC, Hibernate, and other technologies. Thus there’s no need of writing many codes. It encapsulates the basic steps in the given technologies.
- Spring applications are coupled loosely because of interdependency.
- The Dependency Injection provided by spring makes it easier to test any application.
- Spring is lightweight in terms of size and transparency.
- The Dependency Injection feature provided by spring makes the development of Java EE application easy.
- Spring provides power abstraction to Java-like JDBC, JPA, JTA, and JMS.
- Spring also provides caching, formatting, validating and transactions.
5) What are the various components of a spring application?
- Interface: The functions in spring are defined by the interface.
- Bean class: It consists of the properties, its setter-getter methods, other functions etc.
- Spring Aspect Oriented Programming (AOP): In spring AOP provides for the functionality of crosscutting concerns.
- User program: It uses the function to implement.
6) What are the various ways in which Spring Framework can be used?
- It can be used as a full time Spring web application.
- Using Spring Frameworks middle-tier, it can be used as a third-party web framework.
- It can be used for remote usage.
- It can be used as Enterprise Java Bean which has the capability to wrap existing Plain Old Java Objects (POJO)
7) What do you mean by Spring IOC Container?
8) What are the types of Dependency Injection supported by spring?
- Setter Injection : Setter based Dependency Injection can be initialized by calling setter methods on the beans of the user after starting a no argument constructor to initialize their bean.
- Constructor Injection: Constructor based Dependency Injection is initialized by starting a constructor with a number of arguments, each working as a collaborator.
9) What are the differences between constructor injection and setter injection?
- In constructor injection, there’s no partial injection while setter injection provides for partial injection.
- Constructor injection overrides the setter property while setter injection overrides the constructor property.
- Constructor injection creates a new instance for any kind of modification while setter injection doesn’t.
- Constructor injection works better for many properties while setter injection works better for few properties.
10) What are the differences between Bean Factory and Application Context?
- Bean Factory is an interface defined in org.springframework.beansfactory.BeanFactory, while Application Context is an interface defined, is org.springframework.context.ApplicationContext
- While the former uses lazy initialization the latter uses aggressive initialization
- While the former explicitly provide for resource object using the syntax the latter creates and manages resource objects on its own
- The former doesn’t support internationalization while the latter does.
- The former doesn’t support annotation-based dependency while the latter does.
11) What do you mean by AOP?
12) What is an Advice? What are the different types of Advices?
Various types of advice are as follows:
- Before: These are types of advices, which get executed before the join point methods and can be configured using @Before annotation mark.
- After returning: These are the types of advices which get executed after the join point methods completes executing and the annotation mark used to configure it is @AfterReturning
- After throwing: These are the types of advices that execute only and only if join point method returns by exiting an exception and annotation mark used to configure it is @AfterThrowing.
- After (finally): These are the types of advices which gets executed after a join point method, not concerning whether the method’s exit normally or exceptional return and it can be configured using @After annotation mark.
- Around: These are the types of advices that get executed before and after a join point and can be configured using the @Around annotation mark.
13) What do you mean by spring beans? What does bean scopes spring support? Explain each.
The Spring Framework makes use of five scopes. Three of these scopes are valid only if it is in the form of a web-aware Application Context.
- Singleton: This is the scope that the bean defines to a single instance for each Spring IoC container.
- Prototype: This is the scopes that a bean defines to have any number of object instances.
- Request: This is the scopes that a bean defines as per HTTP requests. This is valid in the form of a web-aware Spring Application Context
- Session: This is the scopes that a bean defines to an HTTP session. This is valid in the form of a web-aware Spring Application Context
- Global-session: This is the scopes that a bean defines to a global HTTP session. This is valid in the form of a web-aware Spring Application Context.
14) In how many ways, can one configure Spring into an application?
- Using XML Configuration
- Using Annotation configuration
- Using Java configuration
15) What are the disadvantages of auto wiring?
- Overriding possibility – Despite using auto wiring one can still use dependencies like <property> and <constructor-arg> settings, which always can override auto wiring.
- Primitive data types − one cannot auto wire some simple properties like classes, strings, and primitives etc.
- Confusing nature – Auto wiring is less exact than explicit wiring and thus it is not preferred if explicit wiring can be used.
16) What is an Aspect?
17) What is a Join point?
18) What is a bean definition made up of?
- How bean can be created
- Details about the bean’s lifecycle
On what factors Bean’s lifecycle depends
19) What do you mean by Pointcut?
20) What does Weaving mean?
21) How to use spring boot to configure different datasources ?
22) What is difference between Getmapping and Postmapping in Spring?
Major difference between Getmapping and Postmapping
Getmapping: Getmapping is a Spring notation and is widely used in mapping HTTP GET requests onto some specific handler methods. Getmapping is not generally used in mapping handler classes. This feature differentiates getmapping and requestmapping annotation from each other. It can be considered as an annotation that acts as a shortcut of requestmapping annotation. Getmapping requests handler paths onto specific handler methods. The lines of code are comparatively less than that of requestmapping.
Its request method can be framed as method= RequestMethod.GET. Getmapping is a newer annotation that has been developed to overcome the drawbacks of the previous requestmapping. It supports several attributes such as consume like @requestmapping. It is used to determine or map the GET & POST requests together and its method attribute is also not specified as getmapping maps to HTTP Get method always. This is composed of notation that acts as a shortcut for @requestmapping (method = RequestMethod.Get) it is used to get the requests on well defined and specific handler methods. In this notation it supports consumes where the options are-
consumes = "text/plain" consumes = {"text/plain", "application/*"}
Postmapping: The latest version of Spring MVC known as Spring 4.3 bought with it some annotations, and postmapping is one of them. It has the same purpose as @requestmapping . Postmapping along with other new annotations is meta annotated. These annotations are meta-annotated with @requestmapping as per the related value of the "method " element. Postmapping depicts a combination of notation which is also an abbreviation for @requestmapping.
It is used to map out the Get requests only and its method attribute is also not specified as postmapping always maps HTTP post methods. It is composed of a notation that acts as a shortcut for @requestmapping ( method= RequestMethod. Post). When we talk about the shortcut for @requestmapping we talk about @postmapping, it is a composed annotation that can act as it’s shortcut as @ReqeustMapping(method= RequestMethod.POST).
Variants of @requestmapping other than @getmapping and @postmapping are @patchmapping, @putmapping, and @deletemapping.
23) What is an aspect in spring?
In Spring, an aspect is a class that performs enterprise application interests that cut across various classes, such as transaction management and its role looks and smells like it should have structure, but you can't find a way to represent this structure in code with conventional object-oriented techniques. Aspects can be a regular class configured through Spring XML configuration or we can use Spring AspectJ integration to define a class as Aspect employing @Aspect annotation.
Leave A Comment :
Valid name is required.
Valid name is required.
Valid email id is required.