Tech I Enjoy Logo

Custom Search




  Home >> Spring Framework

Spring Framework -> Interview Questions on Spring Framework
This Page is updated as of 16th October 2011 : 

Question:
Spring Integration 2.0 is built on top of which Spring Framework?

Answer: Spring Framework 3.0.5 version is used to operate Spring Integration 2.0. -------- Question: What are the different new types of Adapters support available in Spring Integration 2.0? Answer: TCP/UDP Adapters Twitter Adapters XMPP Adapters FTP/FTPS Adapters SFTP Adapters Feer Adapters -------- Question: What are the various Channels supported by Spring Integration 2.0? Answer: PollableChannel SubscribableChannel PublishSubscribeChannel QueueChannel PriorityChannel RendezvousChannel DirectChannel ExecutorChannel Scoped Channel -------- Question: Which specific usage requirement makes DirectChannel suitable to be used? Answer: In case requirement is to have transaction support across both sides of the channel and to operate message within a single thread and so the same transaction to work with from sender of message to this channel and to the message handler (handleMessage method) DirectChannel will be a matter of choice while working with Spring Integration version 2.0. -------- Question: What is the usage for QueueChannel from Spring Integration version 2.0? Answer: If there are multiple message handlers are listening to a queue and it is expected to pass incoming message to the channel to be delivered to only one receiver, then QueueChannel should be used. -------- Question: What will be usage of ExecutorChannel? Answer: When a channel should dispatch message to a TaskExecutor on arrival, thus not blocking till the message receiver to collect it from this channel. But this channel doesn't support Transaction as does by DirectChannel. -------- Question: How the transaction management is handled for JMS implmentation from Spring Framework version 3.0? Answer: JmsTransactionManager and JmsTemplate from Spring Framework 3.0 can be used for handling managed transaction from a single JMS ConnectionFactory. -------- Question : While using Spring Framework version 3.0, is there any ways to handle asynchronous task execution with Spring's abstraction features? Answer: TaskExecutor and TaskScheduler from Spring Framework version 3.0 can be used for asynchronous task execution and benifiting from Spring's abstraction features. -------- Question: If MessageChannels requiring to control/read/operate on message properties those are sent and received, how can this be done while using Spring Framework Integration module 3.0? Answer: Using Interceptors with MessageChannels for receiving callbacks while pre and/or post conditions are reached while sending and/or receiving operation happens. -------- Question: Can there be any ways to enforce a perticular data type for the message payload to be handled by a channel? Answer: By defining datatype channel configuration with a fully qualified data type in the channel level configuration. --------
Set of Spring Interview Questions as follows:
Spring Interview
Questions 1:
What is Mandatory Dependency for Spring basic Dependency Injection ?
Spring Question
Answer 1:
Logging is the Mandatory Dependency for Spring basic Dependency Injection.
Spring Interview
Questions 2:
Which logging framework is used for providing logging support in Spring ?
Spring Question
Answer 2:
Jakarta Commons Logging API is used as the mandatory logging dependency
in Spring.
Spring Interview
Questions 3:
What are the main Modules present in Spring Core Container ?
Spring Question
Answer 3:
Core module, Bean Module, Context Module, Epression Language Module are
the modules found in Spring Core Container.
Spring Interview
Questions 4:
What are the modules in Spring Data Access/ Integration layer ?
Spring Question
Answer 4:
JDBC Module, ORM Module, OXM Module, JMS Module, Transaction module are
the modules found in Spring's Data Access/Integration layer.
Spring Interview
Questions 6:
What are the modules present in Spring's Web layer ?
Spring Question
Answer 6:
Spring's Web Module, Web-Servlet module, Web-Struts module, 
Web-portal module are present in Spring's web layer.
Spring Interview
Questions 7:
What is the major difference on functionality provided by
Spring's ORM module and OXM module ?
Spring Question
Answer 7:
Spring's ORM module works with Object Relational Mapping tools/frameworks
such as Hibernate, Oracle TopLink, JDO, JPA, iBatis and many more.

While Spring's OXM module works with Object XML Mapping implementations
like JAXB, Castor and many more.
Spring Interview
Questions 8:
What would be your thought on testing Spring components while using JUnit
as testing framework ?
Spring Question
Answer 8:
There is a Test module from Spring that supports testing of Spring components
with JUnit.
Spring Interview
Questions 9:
Can you be able to use Declarative Transaction Management while not
opting for EJB components in the business layer, not even deploying
application in Application server?
Spring Question
Answer 9:
Yes, one can use Declarative Transaction by using Spring's Transaction 
module, but one catch is that it is not supporting transaction
management across multiple resources/distributed transaction in
remote calls.
Spring Interview
Questions 10:
Can you be able to use Spring's Transaction module for working with
declarative transaction management for a POJO , while using JTA
transaction support from the Application Server's JTA implementation ?
Spring Question
Answer 10:
Yes, Spring can be used along with the JTA transaction by using
Spring's Transaction module along with Application Server's JTA
implementation.
Spring Interview
Questions 11:
Does Spring Framework support Transaction context propagation 
across remote calls ?
Spring Question
Answer 11:
No, Spring Framework doesn't support Transaction context propagation
across remote calls.
Spring Interview
Questions 12:
What are the basic steps required while using Spring's Annotation
based declarative transaction management along with a POJO/Bean?
Spring Question
Answer 12:
Spring's declarative transaction management can be applied to a POJO
or Bean by just declaring @Transactional at class level, interface level, 
for method defined in the interface and only for public methods from a 
class. All @Transactional annotations can have appropriate Element defined
as well, like isolation, propagation, noRollbackFor, noRollbackForClassName,
readOnly, rollbackFor, rollbackForClassName, timeout, value etc.
and then declaring <PLACE_HOLDER:annotation-driven/> in the 
applicationContext or equivalent configuration XML file, while PLACE_HOLDER
is the namespace definition that is pointing to the Spring TX XSD file,
can be "http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
Spring Interview
Questions 13:
Why basically there are two different implentation for context loader for 
a web application deplyed onto a Servlet Container? What are those?
Spring Question
Answer 13:
For web application deplyed onto Servlet 2.3 container, absense of Servlet
Listener prompts for usage of ContextLoaderServlet, while web application
on Servlet 2.4 container, can make use of the ContextLoaderListener for loading
Spring based application context.
Spring Interview
Questions 14:
Are there any ways to pass value of property of a bean as NULL ?
Spring Question
Answer 14:
Yes, NULL tag can be used for passing as property's value.
Spring Interview
Questions 15:
If the Value tag is empty then what will be passed as value to the property 
of the bean?
Spring Question
Answer 15:
An empty string "" will be passed as value to the property tag if empty value
tag is present in property tag of a bean such as follows:
>property name=""<>value/<>property/<
Spring Interview
Questions 16:
What is a compound property name in Spring's definition?
Spring Question
Answer 16:
If the name of the property is having multiple/nested property name such as a.b.c
and none of the property's value should be null, except the last one, or else
Null pointer exception will be thrown at runtime.
Spring Interview
Questions 17:
Can there be singleton bean initialized lazily?
Spring Question
Answer 17:
Yes, by using lazy-init="true" in the bean tag, Spring's ApplicationContext
can be instructed not to eagerly instantiate and configure this bean.
But can instantiate this bean on request only.
Spring Interview
Questions 18:
What are the different scopes applicable to Spring bean?
Spring Question
Answer 18:
Various predefined scopes such as singleton, prototype, request, session, global session can be used.
Spring Interview
Questions 19:
Can there be any custom scope that can be defined and used along with other
Spring configurations declaratively and programmatically?
Spring Question
Answer 19:
Yes, one can define custom scope for the bean while scope can be registered
programmatically and can be used in configuration file declaratively.
Spring Interview
Questions 20:
How to handle Spring bean initialization and destruction so as to be able to
write some logic to be executed during construction and destruction?
Spring Question
Answer 20:
Initialization and destruction callbacks can be assigned to specific methods as 
defined in the configuration declaratively or programmatically by the bean class
implementing InitializingBean and DisposableBean interfaces and implementing 
declared methods to receive callbacks.
Following are Spring Interview Questions date 19th Jan 2010:
Spring Interview
Questions 21:
Can there be custom initialization/destruction callback method like init/
destroy defined in Spring?
Spring Question
Answer 21:
Yes, there are predefined attributes in bean tag for user defined callback
methods to be called during initialization/destruction method of bean.
Spring Interview
Questions 22:
What is that attribute?
Spring Question
Answer 22:
default-init-method and default-destroy-method are the attributes for defined
custom / user defined initialization/destruction callback methods of bean.
Spring Interview
Questions 23:
Is there any way to enable lazy initialization of bean defined in Spring's
configuration XML file?
Spring Question
Answer 23:
Yes, the attribute lazy-init with value as true/false that decides whether to
carry out lazy initilization of the corresponding bean or not.
Spring Interview
Questions 24:
What will happen if a singleton-scoped bean has a reference property for 
the bean that has attribute as lazy-init="true"?
Spring Question
Answer 24:
In this case, Spring's container will create the bean wvwn though this is
defined as lazy-init="true" and inject it into the other Spring bean.
that is singleton-scoped.
Spring Interview
Questions 25:
Can you tell difference between Spring's session and globalsession scopes
for the bean?
Spring Question
Answer 25:
Spring's session is some what similar to the HTTP session in case of a web
application, while Spring's globalsession is more useful in case of 
portlet-based web application, where portlets are sharing a global 
HTTP session for a portlet web application.


Spring Interview
Questions 26:
is ther any specific care that should be taken while configuring HTTP request,
HTTP session or HTTP global session scope for a bean in a web-based application,
while this bean is to be injected to another singleton scoped bean?
Spring Question
Answer 26:
Yes, while request, session or global session scopes can be used for scoping
dependency injection, but by default the bean with singleton scope will be 
initialized for once and it will be injected for once the dependent bean with
scope as request/session/globalsession, thus making it not usable for all other 
HTTP client requests, as for any other client request corresponding different 
request/session/globalsession scoped bean may be applicable.
Spring Interview
Questions 27:
How to work with this type of singleton scoped bean behavior of a bean
operating along with request/session/globalsession scoped bean as dependency?
Spring Question
Answer 27:
One way is to use >aop-schema-name:scoped-proxy/< tag for the bean that is 
to be defined with scope as request/session/globalsession. This way the other bean 
that is scoped as singleton will be getting appropriate dependent beans scoped as 
request/session/globalsession.
Spring Interview
Questions 28:
Can you tell any example showing this behavior?
Spring Question
Answer 28:
<bean id="EmployeeRequest" class="example.EmployeeRequest" scope="request">
  <aop-schema-name:scoped-proxy>
</bean>
<bean id="CalculateSalary" class="example.SalaryCalculate">
  <property name="employeeRequest" ref="EmployeeRequest"/>
</bean>
Spring Interview
Questions 29:
For this example you showed just now, having aspectj scoped-proxy.
What will be used either CGLIB-based class proxy or JDK-based dymanic proxy?
Spring Question
Answer 29:
In this case/example, CGLIB-based class proxy will be used.
Spring Interview
Questions 30:
Can you be able to use JDK-based dynamic proxy?
Spring Question
Answer 30:
Yes, by providing a false value to the proxy-target-class attribute of scoped-proxy tag from the aspect schema definition.
Spring Interview
Questions 31:
If the bean "EmployeeRequest" would have implemented an interface, then
which class proxy type is suitable to use?
Spring Question
Answer 31:
JDK-based dynamic proxy can be used in case the bean that has implemented an 
interface and has scoped-proxy tag defined in configuration.


Spring interview Question 32:
  
  What is Java based bean metadata in SpringFramework version 3.0?

Answer :
  
  Various annotations such as @Configuration, @Bean, @DependsOn
  @Primary, @Lazy, @Import, @ImportResource, @Value are added
  in SpringFramework version 3.0 as part of Java based bean
  annotations.

Spring interview Question 33:

  What is the pre-requisite for using request, session and global session
  scope for bean in SpringFramework version 3.0, as far as Spring
  ApplicationContext implementation is of concern?

Answer:

  For using scopes such as request, session and global session for
  Beans used in SpringFramework's implementation for ApplicationContext
  is of concern, one should be using a web-aware Spring's ApplicationContext
  implementation such as XmlWebApplicationContext (from the package
  org.springframework.web.context.support) can be used.

Spring interview Question 34:

  What will happen if someone tries to use FileSystemXmlApplicationContext
  or ClassPathXmlApplicationContext class for using request, session and
  global session scopes for beans defined in the Spring's Application Context?

Answer:

  There will be an exception IllegalStateException thrown as the bean scope
  is not known for these implementation of Application context from SpringFramework.

Spring interview Question 35:

  What is the major difference over the definition of Singleton, as we know
  from the GoF Singleton design pattern with that of Spring's Singleton scoped
  bean?

Answer:
  
  GoF Singleton design pattern is the single instance of a class in a Classloader.
  But in SpringFramework, Singleton scoped bean is single instance per container
  per bean.

Spring interview Question 36:

  What would be the default scope for a bean in SpringFramework configuration
  if the scope attribute is not mentioned in the bean tag?

Interview Answer:

  By default scope for a bean is Singleton, when there is no scope attribute
  value mentioned for that bean in the Spring configuration file.

    Some Interview questions on Spring MVC as follows:
Spring Web MVC Interview Question : What is a key design principle in Spring web MVC ? Spring Web MVC Interview Answer : "Open for extension and closed for modification" is a key design principle in Spring Web MVC. Spring Web MVC Interview Question : What represents a Model in Spring's MVC architecture? Spring Web MVC Interview Answer : Spring's Model is based on Map interface, so by this abstraction of Model, loose coupling between View and Model is achieved in Spring Web MVC implementation. Spring Web MVC Interview Question : In Spring's Web MVC Architecture, is it required to have the Model class uses framework specific class or interface? Spring Web MVC Interview Answer : No, it is not required to have the model implementation depend on Spring's Framework specific class or interface. Spring's Model can be a POJO with no dependency on Spring's Framework class files. Spring Web MVC Interview Question : In Spring Web MVC, can the Controller implementation be able to write directly to the output/response stream? Spring Web MVC Interview Answer : Yes, in Spring Web MVC, Controller can write content to the output/response stream. Spring Web MVC Interview Question : What are the ways one can achive view resolution in Spring Web MVC? Spring Web MVC Interview Answer : One can achive view resolution in Spring Web MVC by view configuration using bean names, a properties file or custom ViewResolver implementation by user.
    Following Questions are added in this page by Author as of dated 04-Nov-2011:
Spring Web Interview Question : What are the various View Resolvers available with Spring Framework version 3.0? Spring Web Interview Answer : Various View Resolvers available with Spring Framework version 3.0 web module are XsltViewResolver, InternalResourceViewResolver, ResourceBundleViewResolver, UrlBasedViewResolver, VelocityViewResolver, XmlViewResolver, VelocityLayoutViewResolver, FreeMarkerViewResolver, BeanNameViewResolver, ContentNegotiatingViewResolver, JasperReportsViewResolver, TilesViewResolver. Spring Web Interview Question : Are there any view resolver those having caching mechanism associated with? If yes, what are those view resolver? Spring Web Interview Answer : ResourceBundleViewResolver, UrlBasedViewResolver, XmlViewResolver are the resolvers those are having caching mechanism associated with these. Spring Web Interview Question : Are there any view resolvers those use Templating for rendering view elements? Spring Web Interview Answer : FreeMarkerViewResolver, VelocityViewResolver are those view resolvers having support for Templating capabilities. Spring Web MVC Module Interview Question : How input data validation is handled while using Spring's Web MVC? Answer : Input data type mismatch is captured as validation error while working with Spring Web MVC Framework. Spring Web MVC Module Interview Question : Can any object be used as command while using Spring Framework Web MVC? Answer : Yes, any object can be used as Command object while using Spring Web MVC. Spring Web MVC Module Interview Question : Is it possible to write directly to the response stream from Spring's Controller ? Answer : Yes, while working with Spring's Web MVC Controller, one can write directly to the response stream. Spring Web MVC Module Interview Question : What basic elements ModelAndView instance contains? Answer : View name and Model as Map element can be found in ModelAndView instance. Spring Web MVC Module Interview Question : What are the different values a View element can have? Answer : View name/value can be bean name, a properties file name or a custom ViewResolver name. Spring Web MVC Module Interview Question : From design/abstraction perspective how Spring Framework's Web MVC module uses various UI rendering technologies/ frameworks? Answer : As Model element from Spring's Web MVC Module is based on Map interface, one can easily integrate various UI rendering technologies such as JSP, XSLT, JSTL, Velocity Templates, PDF and many more utilities. Spring Web MVC Module Interview Question : What are the various Special beans instances can be found/associated with Spring's WebApplicationContext instance? Answer : Controller instance, Handling mapping, various resolvers such as view resolvers, locale resolvers, Theme resolver, exception handler resolvers, multipart file resolvers. Spring Web MVC Module Interview Question : While using Spring's Web MVC module, how one can define/configure to use Controller? Answer : Any POJO can be used as cotroller either by defining the POJO class in the *-servlet.xml file (whereby * is to be replaced by the servlet-name from web.xml descriptor file) as bean or by using @Controller annotation (in case of appropriate version of Spring Framework with support for annotations). Spring Web MVC Module Interview Question : How the method from controller class file that is to be executed is identified from the request? Answer : Either by using approriate Request Handler class file that is defined in the configuration XML file as bean or by using annotation @RequestMapping with definition for request URI etc., for any method that is to be executed based on request pattern/URI. Spring Web MVC Module Interview Question : Presence of request parameters with value in request object might need to be mapped to appropriate configured method parameters, Is it possible, if yes then how? Answer : If annotation is supported, then Request level parameters and its value can be mapped to controller method argument by using @RequestParam annotation. Spring Web MVC Module Interview Question : What is the significance of @RequestBody annotation? Answer : Annotation @RequestBody can be used at method level to accept body part of request object as a parameter value of type String. Spring Web MVC Module Interview Question : How to send reponse data directly to the response object without adding it to the Model or not to be considered as view name? Answer : By using annotation @ResponseBody tagged to a method for making the return value from the same method added to the response body, and not making it as Model value or as view name.
If anything missed out , please let me know at techienjoy at yahoo . com
Example using Spring DAO with Hibernate :
Example using Spring DAO with Hibernate Framework Part 2.
Spring Framework Remote Session Bean :
Spring Framework Example source code of
Remote Session Bean.
Interview Questions with answer on Spring Framework :
Interview Questions with answer on Spring Framework.
Spring Framework Web Example and WSDL :
Spring Framework Web Example source code
with WSDL.Step by step code walkthrough
Spring Framework Local Stateless Session bean :
Spring Framework Local Stateless Session bean with
example source code explained.
Example using Spring DAO with Hibernate :
Example using Spring DAO with Hibernate Framework.
Spring Batch Framework Example :
Spring Batch Framework Example source code
 and Step by step code walkthrough
Spring Framework Web Example :
Spring Framework Web Example source code Explained.
Spring Framework Example :
Spring Framework Example source code Explained.
Step by step code walkthrough
Example using Spring with Hibernate :
Example using Spring with Hibernate Framework and use
Current Session Context.
Spring Framework MVC and Tiles :
Spring Framework MVC and Tiles with Example 
source code explained.
Spring Framework Singleton Example :
Spring Framework Singleton Example source code 
compared with GOF Singleton.
Spring Framework Web Example :
Spring Framework Web Example source code Explained.
Example using Spring with Hibernate :
Example using Spring with Hibernate Framework Part 1.
Example using Spring with Hibernate :
Example using Spring with Hibernate Framework Part 2.


References :
Tags: spring dao hibernate example
Tags: spring hibernate dao example
Tags: spring hibernate example 2
Tags: spring hibernate example current session context
Tags: spring hibernate example
Tags: Spring Interview Questions Answer
Tags: Spring Local SLBean
Tags: Spring MVC Tiles2
Tags: Spring Remote SLBean
Tags: Spring Singleton GOF Singleton Difference
Tags: spring web example
Tags: spring ws example
Tags: Spring
Tags: springws example wsdl



DISCLAIMER :
The content provided in this page is not warranted and/or guaranteed by techienjoy.com. 
techienjoy.com is not liable for any negative consequences that may result/arise from 
implementing directly/indirectly any information covered in these pages/articles/tutorials.

All contents of this site is/are written and provided on an "AS IS" basis,
without WARRANTIES or conditions of any kind, either express or implied, including, without
limitation, merchantability, or fitness for a particular purpose. You are solely responsible
for determining the appropriateness of using or refering this and assume any risks associated
with this.

In spite of all precautions taken to avoid any typo in these pages, there might be some 
issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
extends sincerest apologies to all our visitors for the same.



Android Examples || Android Examples

© Copyright 2010-2012, TECHIENJOY, All Rights Reserved.      Privacy Policy     Disclaimer & Terms & Conditions