Spring MVC Interview Questions and Answers: Minutes
Spring MVC Interview Questions and Answers: Minutes
Reusability
Decoupling
Framework
IOC
AOP
Web module
ApplicationContext allows more than one config files to exist while BeanFactory only
permits one.
no: no autowire
RequestHandledEvent This event is called when the web context handles request
Setter Injection
Constructor Injection
byName
byType
constructor
autodetect
29) What are the types of the transaction management that is supported by
spring?
Following are the types of transaction management that has been supported by spring:
declarative
programmatically
RequestHandledEvent This gets called when the web context is handling a request.
Advice will tell application on new behavior and it is the implementation of an aspect. It is
inserted into an application at the joinpoint.
Advice is the implementation of an aspect. It is something like telling your application of a
new behavior. Generally, the advice is inserted into an application at joinpoints.
36) What is a Pointcut?
Pointcut is used to allow where the advice can be applied.
37) What is weaving?
Weaving is used to create new proxy object by applying aspects to target object.
38) What is difference between singleton and prototype bean?
Singleton Bean Single bean definition to a single object instance per Spring IOC container
Prototype Bean Single bean definition to any number of object instances per Spring IOC
Container
39) In what points, can weaving be applied?
Following are the points where weaving can be applied:
Compile Time
Runtime
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
Metadata autoproxying
SmartData Source
AbstractData Source
SingleConnection DataSource
DriverManager DataSource
TransactionAware DataSourceProxy
DataSource TransactionManager
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
PropertyEditor
URLEditor
ClassEditor
CustomDateEditor
FileEditor
LocaleEditor
StringArrayPropertyEditor
StringTrimmerEditor
Layered Architecture
Enables Plain Old Java Object (POJO) Programming and it enables continuous
integration and testability
Pollable Channel
Subscribable Channel
PublishSubscribe Channel
Queue Channel
Priority Channel
Rendezvous Channel
Direct Channel
Executor Channel
Scoped Channel
Configuration of Spring to manage beans using ContextLoader plugin and set their
dependencies in a spring context file
Grab spring managed beans explicitly using agetwebapplicationcontext()
56) What is Inversion of control (IOC)?
Inversion of Control (IOC) is also called as dependency Injection which is nothingbut a design
pattern that gives control to the assembler of classes. In general, class will instantiate
another class if required.
But in this design pattern, this control has been to given to assembler and assembler will
instantiate required class if needed.
57) Write the benefits of using IOC?
The major benefits of dependency injection or IOC are that it reduces the amount of coding
required for the application. This allows the testing of the application to be done quickly and
easily as no JNDI lookup mechanism or singletons are required. IOC containers also support
lazy loading and eager installation of services.
58) What is Inner bean? What is the drawback of inner bean?
If a bean element is directly embedded in a property tag while wiring beans, then the bean
is called Inner Bean. Its drawback is that it cannot be reprocessed.
59)What are the different types of Injection in spring?
There are three types of Injection in spring:
Setter Injection
Constructor Injection
Before Advice
Finally advice
Around advice
int getBatchSize
ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
XmlWebApplicationContext
1
2
3
4
5
6
7
8
9
1
0
1
1
The bean tag has an ID attribute which stores the bean name and a class attributes which
specifies the full class name.
70) What are ORM integration modules?
Object/relational mapping (ORM) tool is supported by Spring over straight JDBC by
implementing the ORM module. Spring can join various important ORM frameworks,
including JDO, iBATIS SQL Maps and Hibernate.
71) Mention and explain the types of Advice in Spring?
Types of advice are:
Before advice: Advice that is executed prior to a joinpoint is called the before
advice.
After returning advice: Advice that is executed after the normal completion of
a joinpoint is called the after returning advice.
After throwing advice: Advice that is executed only if a method exits abnormally by
throwing an exception, is called the after throwing advice.
After (finally) advice: Advice that is executed irrespective of how a joinpoint exits is
called after finally advice.
Around advice: Advice that borders a joinpoint, for example, a method invocation, is
called an around advice. This can be used to perform special activities before and after
the invocation of method.
Out of these three, only construction and setter are being used in Spring.
77) What are the important beans lifecycle methods?
All in all, two bean lifecycle methods are there. The first method is the setup method which
is called during the loading of the bean into the container. The second is when the bean is
unloaded from the container, and this method is called the teardown.
78) How can the default lifecycle methods of beans be nullified?
The tag, bean, has two useful attributes which can be used to define special initialization
and destruction methods.
For Example, two new methods forSetup and forTeardown can be added to the Foo class in
the following way:
1 <beans>
2
3 <bean id="bar" init-method=forSetup destroy=forTeardown/>
4
5 </beans>
79) What is a Target?
A target is the class that is advised. This class can either be a class to which we want to add
a special behavior to or a third party class. The target class is free to center on its major
concern using the AOP concepts, regardless of any advice that is being applied.
80) Explain the term Proxy?
The term proxy refers to an object which is produced the application of an advice to the
target object.
81) What is cross cutting concern and concern in spring AOP?
Cross cutting concern: It is a concern which is applicable throughout the application and it
affects the
entire application. E.g Security, logging and data transfer are the concerns