You are on page 1of 10

Page 1 of 10

What is Spring?
Spring is great framework for development of Enterprise grade applications. Spring is a light-weight framework for the
development of enterprise-ready applications. Spring can be used to configure declarative transaction management,
remote access to your logic using RMI or web services, mailing facilities and various options in persisting your data to
a database. Spring framework can be used in modular fashion, it allows to use in parts and leave the other
components which is not reuired by the application.
Features of Spring Framework:
Transaction Management: Spring framework provides a generic abstraction layer for transaction
management. !his allowing the developer to add the pluggable transaction managers, and making it easy to
demarcate transactions without dealing with low-level issues. Spring"s transaction support is not tied to #$EE
environments and it can be also used in container less environments.
JDBC Exception an!"ing: !he #%&' abstraction layer of the Spring offers a meaningful e(ception
hierarchy, which simplifies the error handling strategy

#ntegration with i$ernate% JD&% an! iB'T#S: Spring provides best Integration services with
)ibernate, #%* and i&+!IS.

'&( Framework: Spring is best +*, framework

M)C Framework: Spring comes with M-' web application framework, built on core Spring functionality.
!his framework is highly configurable via strategy interfaces, and accommodates multiple view technologies
like #S,, -elocity, !iles, i!e(t, and ,*I. &ut other frameworks can be easily used instead of Spring M-'
.ramework..
Spring 'rchitecture
Spring is well-organi/ed architecture consisting of seven modules. Modules in the Spring framework are0
1. Spring '&(
*ne of the key components of Spring is the AOP framework. +*, is used in Spring0
!o provide declarative enterprise services, especially as a replacement for E#& declarative
services. !he most important such service is declarative transaction management, which builds on
Spring"s transaction abstraction.
!o allow users to implement custom aspects, complementing their use of **, with +*,
$. Spring &*M
!he ORM package is related to the database access. It provides integration layers for popular ob2ect-
relational mapping +,Is, including #%*, )ibernate and i&atis.

3. Spring We$
!he Spring 4eb module is part of Spring5s web application development stack, which includes Spring M-'.

Page 2 of 10
6. Spring D'&
!he %+* 7%ata +ccess *b2ect8 support in Spring is primarily for standardi/ing the data access work using
the technologies like #%&', )ibernate or #%*.

9. Spring Context
!his package builds on the beans package to add support for message sources and for the *bserver design
pattern, and the ability for application ob2ects to obtain resources using a consistent +,I.

:. Spring We$ M)C
!his is the Module which provides the M-' implementations for the web applications.

;. Spring Core
!he Core package is the most import component of the Spring .ramework.
!his component provides the %ependency In2ection features. !he &ean.actory provides a factory pattern
which separates the dependencies like initiali/ation, creation and access of the ob2ects from your actual
program logic.
The fo""owing !iagram represents the Spring Framework 'rchitecture
Page 3 of 10
Spring Framework 'rchitecture
+, Spring an! #n-ersion of Contro"
There is a lot of confusion about the definition of the IoC container some equate it with a design
pattern calledDependency Injection but in reality IoC is much larger than dependency injection.
The Spring IoC container enforces dependency injection in its various forms and employs a number of
established design patterns to achieve this.
The main idea behind Inversion of Control as a concept is that component dependencies, lifecycle
events, and configuration reside outside of the components themselves, and in the case of Spring, in
the framewor. This may sound a bit lie giving up too much control, but in fact it can mae your code
more manageable, more testable, and more portable.
Important Questions
Page 4 of 10
+. What is Spring Framework :
Spring is a lightweight inversion of control and aspect-oriented container framework. Spring .ramework<s
contribution towards 2ava community is immense and spring community is the largest and most innovative community
by si/e. !hey have numerous pro2ects under their portfolio and have their own spring dmServer for running spring
applications. !his community is acuired by -M4are, a leading cloud compting company for enabling the
2ava application in the cloud by using spring stacks. If you are looking to read more about the spring framework and
its products, please read in their official site Spring Source.
/. Exp"ain Spring :
0ightweight : Spring is lightweight when it comes to si/e and transparency. !he basic version of spring
framework is around 1M&. +nd the processing overhead is also very negligible.
#n-ersion of contro" 1#oC. : =oose coupling is achieved in spring using the techniue Inversion of 'ontrol.
!he ob2ects give their dependencies instead of creating or looking for dependent ob2ects.
'spect oriente! 1'&(. : Spring supports +spect 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 ob2ects.
Framework : Spring provides most of the intra functionality leaving rest of the coding to the developer.
2. What are the !ifferent mo!u"es in Spring framework :
!he 'ore container module
+pplication conte(t module
+*, module 7+spect *riented ,rogramming8
#%&' abstraction and %+* module
*>R mapping integration module 7*b2ect>Relational8
4eb module
MVC framework module
Page 5 of 10
3. What is the structure of Spring framework :
4. What is the Core container mo!u"e :
!his module is provides the fundamental functionality of the spring framework. In this moduleBeanFactor5 is the
heart of any spring-based application. !he entire framework was built on the top of this module. !his module makes
the Spring container.
6. What is 'pp"ication context mo!u"e :
!he +pplication conte(t module makes spring a framework. !his module e(tends the concept ofBeanFactory,
providing support for internationali/ation 7I1?@8 messages, application lifecycle events, and validation. !his module
also supplies many enterprise services such #@%I access,EJB integration, remoting, and scheduling. It also
provides support to other framework.
7. What is '&( mo!u"e :
!he AOP module is used for developing aspects for our Spring-enabled application. Much of the support has been
provided by the +*, +lliance in order to ensure the interoperability between Spring and other AOP frameworks. !his
module also introduces metadata programming to Spring. Asing Spring<s metadata support, we will be able to
add annotations to our source code that instruct Spring on where and how to apply aspects.
8.What is JDBC a$straction an! D'& mo!u"e :
Asing this module we can keep up the database code clean and simple, and prevent problems that result from a
failure to close database resources. + new layer of meaningful e(ceptions on top of the error messages given by
several database servers is bought in this module. In addition, this module uses Springs AOP modue to provide
transaction management services for ob2ects in a Spring application.
9. What are o$:ect;re"ationa" mapping integration mo!u"e :
Spring also supports for using of an ob2ect>relational mapping 7*RM8 tool over straight #%&' by providing the *RM
module. Spring provide support to tie into several popular O!M frameworks, including "i#ernate, J$O, and iBA%&S
S'( Maps. Spring<s transaction management supports each of these O!M frameworks as well as J$BC.
Page 6 of 10
+<. What is we$ mo!u"e :
!his module is built on the application conte(t module, providing a conte(t that is appropriate for web-based
applications. !his module also contains support for several web-oriented tasks such as transparently handling
multipart reuests for file uploads and programmatic binding of reuest parameters to your business ob2ects. It also
contains integration support with Jakarta Struts.
++. What is we$ mo!u"e :
Spring comes with a full-featured M-' framework for building web applications. +lthough Spring can easily be
integrated with other M-' frameworks, such as Struts, Spring<s M-' framework uses Io' to provide for a clean
separation of controller logic from business ob2ects. It also allows you to decoratively bind reuest parameters to your
business ob2ects. It also can take advantage of any of Spring<s other services, such as I1?@ messaging and
validation.
+/. What is a BeanFactor5 :
+ &ean.actory is an implementation of the factory pattern that applies Inversion of 'ontrol to separate the
application<s configuration and dependencies from the actual application code.
+2. What is '&( '""iance :
+*, +lliance is an open-source pro2ect whose goal is to promote adoption of +*, and interoperability among
different +*, implementations by defining a common set of interfaces and components.
+3. What is Spring configuration fi"e :
Spring configuration file is an BM= file. !his file contains the classes information and describes how these classes are
configured and introduced to each other.
+4. What !oes a simp"e spring app"ication contain :
!hese applications are like any #ava application. !hey are made up of several classes, each performing a specific
purpose within the application. &ut these classes are configured and introduced to each other through an BM= file.
!his BM= file describes how to configure the classes, known as the Spring configuration file.
+6. What is =M0BeanFactor5 :
BeanFactory has many implementations in Spring. &ut one of the most useful one
isorg)springframework)#eans)factory)*m)+mBeanFactory, which loads its beans based on the definitions
contained in an BM= file. !o create an +mBeanFactory, pass a 2ava.io.InputStream to the constructor.
!he &nputStream will provide the BM= to the factory. .or e(ample, the following code snippet uses a
2ava.io.Fie&nputStream to provide a bean definition BM= file to +mBeanFactory.
1
2
BeanFactory factory = new XmlBeanFactory(
new FileInputStream("beans.xml"));
!o retrieve the bean from a &ean.actory, call the get&ean78 method by passing the name of the bean you want to
retrieve.
1
MyBean myBean = (MyBean) factory.etBean("myBean");
Page 7 of 10
+7. What are important 'pp"icationContext imp"ementations in spring framework :
C"ass(ath=m"'pp"icationContext > !his conte(t loads a conte(t definition from an BM= file located in the
class path, treating conte(t definition files as class path resources.
Fi"eS5stem=m"'pp"icationContext > !his conte(t loads a conte(t definition from an BM= file in the
filesystem.
=m"We$'pp"icationContext > !his conte(t loads the conte(t definitions from an BM= file contained within
a web application.
+8. Exp"ain Bean "ifec5c"e in Spring framework :
+, !he spring container finds the bean<s definition from the BM= file and instantiates the bean.
/, Asing the dependency in2ection, spring populates all of the properties as specified in the bean definition.
2, If the bean implements the Bean?ame'ware interface, the factory calls setBean?ame1.passing the bean<s
I%.
3, If the bean implements the BeanFactor5'ware interface, the factory callssetBeanFactor51., passing an
instance of itself.
4, If there are any Bean(ost(rocessors associated with the bean, their post@
(rocessBefore#nitia"iAation1. methods will be called.
6, If an init-method is specified for the bean, it will be called.
7, .inally, if there are any Bean(ost(rocessors associated with the bean,
theirpost(rocess'fter#nitia"iAation1. methods will be called.
8,
+9. What is $ean wiring :
'ombining together beans within the Spring container is known as bean wiring or wiring. 4hen wiring beans, you
should tell the container what beans are needed and how the container should use dependency in2ection to tie them
together.
/<. ow !o a!! a $ean in spring app"ication :
1
2
3
4
5
6
7
!"xml #ersion="$.%" enco&in="'(F)*""+
!,-./(012 beans 1'B3I/ ")44S15I6744-(- B2864426"
"9ttp:44www.sprinframewor;.or4&t&4sprin)
beans.&t&"+
!beans+
!bean i&="foo" class="com.act.Foo"4+
!bean i&="bar" class="com.act.Bar"4
!4beans+
In the bean tag the id attribute specifies the bean name and the class attribute specifies the fully ualified class name.
Page 8 of 10
/+. What are sing"eton $eans an! how can 5ou create protot5pe $eans :
&eans defined in spring framework are singleton beans. !here is an attribute in bean tag named Csingleton< if
specified true then bean becomes singleton and if set to false then the bean becomes a prototype bean. &y default it
is set to true. So, all the beans in spring framework are by default singleton beans.
1
2
3
!beans+
!bean i&="bar" class="com.act.Foo"
sinleton="false"4+
!4beans+
//. What are the important $eans "ifec5c"e metho!s :
!here are two important bean lifecycle methods. !he first one is setup which is called when the bean is loaded in to
the container. !he second method is the teardown method which is called when the bean is unloaded from the
container.
/2. ow can 5ou o-erri!e $eans !efau"t "ifec5c"e metho!s :
!he bean tag has two more important attributes with which you can define your own custom initiali/ation and destroy
methods. )ere I have shown a small demonstration. !wo new methods fooSetup and foo!eardown are to be added
to your .oo class.
1
2
3
4
!beans+
!bean i&="bar" class="com.act.Foo"
init)met9o&="fooSetup" &estroy="foo(ear&own"4+
!4beans+
/3. What are #nner Beans :
4hen wiring beans, if a bean element is embedded to a property tag directly, then that bean is said to the Inner &ean.
!he drawback of this bean is that it cannot be reused anywhere else.
/4. What are the !ifferent t5pes of $ean in:ections :
!here are two types of bean in2ections.
1. &y setter
$. &y constructor
/6. What is 'uto wiring :
Dou can wire the beans as you wish. &ut spring framework also does this work for you. It can auto wire the related
beans together. +ll you have to do is 2ust set the autowire attribute of bean tag to an autowire type.
1
!beans+
Page 9 of 10
2
3
!bean i&="bar" class="com.act.Foo"
8utowire="autowire type"4+
!4beans+
/7. What are !ifferent t5pes of 'utowire t5pes :
!here are four different types by which autowiring can be done.
o by@ame
o by!ype
o constructor
o autodetect
/8. What are the !ifferent t5pes of e-ents re"ate! to 0isteners :
!here are a lot of events related to 'pp"icationContext of spring framework. +ll the events are subclasses
of org,springframework,context,'pp"ication@E-ent. !hey are
'onte(t'losedEvent E !his is fired when the conte(t is closed.
'onte(tRefreshedEvent E !his is fired when the conte(t is initiali/ed or refreshed.
Reuest)andledEvent E !his is fired when the web conte(t handles any reuest.
/9. What is an 'spect :
+n aspect is the cross-cutting functionality that you are implementing. It is the aspect of your application you are
modulari/ing. +n e(ample of an aspect is logging. =ogging is something that is reuired throughout an application.
)owever, because applications tend to be broken down into layers based on functionality, reusing a logging module
through inheritance does not make sense. )owever, you can create a logging aspect and apply it throughout your
application using +*,.
2<. What is a Jointpoint :
+ 2oinpoint is a point in the e(ecution of the application where an aspect can be plugged in. !his point could be a
method being called, an e(ception being thrown, or even a field being modified. !hese are the points where your
aspect<s code can be inserted into the normal flow of your application to add new behavior.
2+. What is an '!-ice :
+dvice is the implementation of an aspect. It is something like telling your application of a new behavior. Fenerally,
and advice is inserted into an application at 2oinpoints.
2/. What is a (ointcut :
+ pointcut is something that defines at what 2oinpoints an advice should be applied. +dvices can be applied at any
2oinpoint that is supported by the +*, framework. !hese ,ointcuts allow you to specify where the advice can be
applied.
22. What is an #ntro!uction in '&( :
+n introduction allows the user to add new methods or attributes to an e(isting class. !his can then be introduced to
an e(isting class without having to change the structure of the class, but give them the new behavior and state.
Page 10 of 10
23. What is a Target :
+ target is the class that is being advised. !he class can be a third party class or your own class to which you want to
add your own custom behavior. &y using the concepts of +*,, the target class is free to center on its ma2or concern,
unaware to any advice that is being applied.
24. What is a (rox5 :
+ pro(y is an ob2ect that is created after applying advice to a target ob2ect. 4hen you think of client ob2ects the target ob2ect and the pro(y
ob2ect are the same.
26. What is meant $5 Wea-ing :
!he process of applying aspects to a target ob2ect to create a new pro(y ob2ect is called as 4eaving. !he aspects are woven into the target
ob2ect at the specified 2oinpoints.
27. What are the !ifferent points where wea-ing can $e app"ie! :
'ompile !ime
'lassload !ime
Runtime
28. What are the !ifferent a!-ice t5pes in spring :
o 'roun! : Intercepts the calls to the target method
o Before : !his is called before the target method is invoked
o 'fter : !his is called after the target method is returned
o Throws : !his is called when the target method throws and e(ception
+round 0 org.aopalliance.intercept.MethodInterceptor
&efore 0 org.springframework.aop.&efore+dvice
+fter 0 org.springframework.aop.+fterReturning+dvice
!hrows 0 org.springframework.aop.!hrows+dvice
29. What are the !ifferent t5pes of 'uto(rox5ing :
&ean@ame+uto,ro(y'reator
%efault+dvisor+uto,ro(y'reator
Metadata autopro(ying
3<. What is the Exception c"ass re"ate! to a"" the exceptions that are thrown in spring
app"ications :
1
2
-ata8ccess2xception )
or.sprinframewor;.&ao.-ata8ccess2xception

You might also like