Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Spring Tutorials >>> Interview Question >>> SpringFramework
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : ISHTEK
Title :
Spring singleton
Description : Spring Container Example
More...


Written By : ISHTEK
Title :
Spring Features Updates News
Description : Bringing To Page
More...


Written By : ISHTEK
Title :
Spring Service
Description : Web Service Example
More...


Written By : ISHTEK
Title :
Spring WebService
Description : Example Code Discussed
More...


Written By : Amit
Title :
Spring Web MVC
Description : Example code discussed
More...


Written By : ISHTEK
Title :
Spring Remote Stateless SessionBean
Description : Calling SessionBean Example code
More...


Written By : ISHTEK
Title :
Spring Local Stateless SessionBean
Description : Calling Local SessionBean Example code
More...


Written By : guddu
Title :
Struts 2 Spring
Description : Integration Example and Details
More...

Tags/Keywords : Spring interview questions, Spring, Interview, Questions, Example, Code, Tutorial, Article
Author : Amit
Date (Year/Month/Date): 2009-02-05 Question 1 : How to use SpringFramework in an Enterprise wide Cluster environment/setup where web and EJB Containers are located in separate nodes? Please Reply after login or register Question 2 : How to setup SpringFramework and JPA implementation such as OpenJPA in APP or EJB container of Application Server? Please Reply after login or register Question 3 : How to configure SpringFramework so as to use JTA transaction in a web based application deployed on JBoss application server? Please Reply after login or register

Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this 
as it is without appropriate evaluation to their, so to say, 
specific programming context.

This page intends only to provide bit and piece of known ways  for
doing some sort of example and may not be fit for any other purpose.

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.

Advertisement :
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.

Advertisement :


	

Commented By ->
Amit
Friends!!

Please find here with my comment, some of the questions may be asked
in an interview session for SpringFramework .

Please correct me if any of these questions/corresponding answer
is not correct/applicable.

Spring interview question 1:
How can Circular dependencies occur while using Sprin IOC, give an example?

Spring interview answer :
If a bean has another bean as argument type in constructor, and vice versa
(the later bean has the former bean as argument type passed in constructor),
then a Circular dependencies can occur. In this circular dependency, Spring will
throw BeanCurrentlyInCreateionException, if the constructor injection is used.

Spring interview question 2:
How to avoid BeanCurrentlyInCreateionException being thrown at runtime,
or how to avoid a circular dependency to be found by Spring at runtime?

Spring interview answer :
One way is to avoid using constructor injection, instead going for setter
injection will be good idea (of course one has to look at other aspects
of the requirement as well before deciding which type of injection to be
used), to avoid BeanCurrentlyInCreateionException from Spring at runtime.

Spring interview question 3:
While using SpringFramework, can a bean be declared as anonymous?

Spring interview answer :
Yes, it is possible to define bean as anonymous, by defining bean inside 
<property> and inside <constructor-arg> tags when defined within
bean tag.

Spring interview question 4:
What is the default scope for the Bean that is defined as anonymous?

Spring interview answer :
Scope is prototype for any bean defined anonymous within property and constructor
tags.

Spring interview question 5:
What are the various Spring elements those can be used with Java Collection types
such as List, Set, Map and Properties?

Spring interview answer :

<list>, <set>, <map> and <props> tags can be with these 
Java Collection types, such as List, Set, Map and Properties.

Commented By ->
Amit
Spring Interview Question :
Which version onwards Spring has Annotation support?

Spring Interview Answer :
Spring version 2.5 onwards has the annotation based configuration
support.

Spring Interview Question :
How do you configure in your application that uses Spring
for using annotation based POJO or Bean coding?

Spring Interview Answer
Generally the Spring configuration XML file, if has a tag as

>config:annotation-config< where config is the schema definition
for the spring context URI such as 
http://www.springframework.org/schema/context

Spring Interview Question
Which annotation that can be along with a constructor, field, setter method
or config methods for enabling Spring' dependency injection along with bean?

Spring Interview answer
@Autowired can be used along with a constructor, field, setter method
or config methods of bean for enabling Spring' dependency injection.

Spring interview question
What is a config method of a bean, can you please elaborate it a bit more,
how is it applicable to any argument(s) of the config method?

Spring interview answer
config method are the custom methods not of setter type, and it can have
any arbitrary number of argument(s) and each of the argument(s) will 
be autowired with matching bean in the Spring container.

Let me show an example showing how to auto wire dependency
beans by using @Autowired annotation and this is using
Spring Framework 3.0 version.

After creating a very simple example with basic Spring
configuration file and setting some of the bean definition
I could able to grasp how this @Autowired annotation works
to some extend. If interested I shall show this in below
writing, please read on if interested.

There will a custom example class as SampleBean and it uses
two custom example class files such as Example and Config
and one java.util.Properties class file.

let us look at the SampleBean as follows:
example.SampleBean
package example;

import java.util.Properties;

public class SampleBean {
  @org.springframework.beans.factory.annotation.Autowired
  private Example example;
  private Config confg;
  private Properties props;
  @org.springframework.beans.factory.annotation.Autowired
  public void configMethod(Config config, Properties prop) {
    confg = config;
    props = prop;
    System.out.println("config method is called:"+config+"\t"+prop);
  }
  public Example getExample() {
	  return example;
  }
  public Properties getProps() {
	  return props;
  }
}

While the Example class and Config class are just simple
POJO with a private variable.

example.Example
package example;
public class Example
{
  private String name = "test value";
  public void setName(String argName) {
    name = argName;
  }
  public String getName() {
    return name;
  }
}
and
example.Config
package example;

public class Config {
  public String logFile;
  
}

Now it is very logical to look at the Spring configuration
file for the Spring Container, as shown below:
sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:ctx="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  <ctx:annotation-config/>
  <bean id="configuration" class="example.Config"/>
  <bean id="config" class="example.Config"/>
  <bean id="prop" class="java.util.Properties"/> 
  <bean id="example1" class="example.Example"/>
  <bean id="sample" class="example.SampleBean">
  </bean>
</beans>

When I ran this example with a test harness/client class as shown
below:

Client
import org.springframework.context.support.ClassPathXmlApplicationContext;

import example.*;
public class Client
{
  public Client() {
    try{
      ClassPathXmlApplicationContext appCtx = 
           new ClassPathXmlApplicationContext("sample.xml");
      SampleBean sb = (SampleBean) appCtx.getBean("sample");
      System.out.println(sb.getExample().getName());
    } catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  public static void main(String args[]) {
    new Client();
  }
}


Output of this Client class after execution, on console I found as 

config method is called:example.Config@15fadcf	{}
test value

This depicts that the private instance variable example of the SampleBean
is auto wired and got the example.Example object injected to it.
And the configMethod method is also got called by autowired annotation.
In this case as there are two bean definition for the Config class
is defined, so Spring choose the one with the id same as the configMethod
argument name. If I remove one bean definition for the Config bean, then
irrespective of the id, always one bean instance will be autowired to this
configMethod of SampleBean.
But if i define two bean definition of the Config bean with different id 
but none same as the argument name of the configMethod, then there will be
a run time exception raised as follows:


org.springframework.beans.factory.BeanCreationException:
.....
.....
Could not autowire method: public void 
    example.SampleBean.configMethod(example.Config,java.util.Properties);
    nested exception is 
    org.springframework.beans.factory.NoSuchBeanDefinitionException: 
    No unique bean of type [example.Config] is defined: expected single
    matching bean but found 2: [configuration, config1]
.....
.....


The above exception I received/seen on console when I ran this example
with the following sample.xml file as Spring configuration file:

sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:ctx="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  <ctx:annotation-config/>
  <bean id="configuration" class="example.Config"/>
  <bean id="config" class="example.Config"/>
  <bean id="prop" class="java.util.Properties"/> 
  <bean id="example1" class="example.Example"/>
  <bean id="sample" class="example.SampleBean">
  </bean>
</beans>

Commented By ->
Amit
Spring Interview questions with answer added in this page on 23rd Feb 2010
Spring Interview Question 1:
What is the exception class that is provided by Spring Framework
while working with data access mechanisms such as JDBC, 
Hibernate, JDO or JPA ?

Answer:
org.springframework.dao.DataAccessException is the root exception
that should used while using Spring's support for data access
layer.

Spring interview question 2:
Spring's DataAccessException is checked or unchecked exception?

Answer:
Spring's DataAccessException is unchecked exception.

Spring's interview question 3:
Is there any Spring's support for datasource that can be used
while testing data access related code outside of J2EE/JEE
container?

Answer:
package org.springframework.jdbc.datasource has many class
files and out of which I have used DriverManagerDataSource
along with Spring's DAO for mocking up data access related
code so as to be able to test code in non J2EE/JEE container,
while using javax.sql.DataSource related API.


Commented By ->
Amit
Some of these interview questions on Spring Framework
(version 3.0) as mentioned below:

1: Can the Controller implementation from Spring MVC Web module be able
   to write to the response stream directly ?

Answer :
   Yes, the Controller implementation that is provided by developer
   while using Spring's Web module, should be able to write content
   directly using the response object/stream.

2: Can you be able to use Spring Framework version 3.0 along with other
   web application frameworks like Struts, JSF etc?

Answer :

   Yes, one can integrate Spring with Struts and JSF by loading
   Spring's application context by using listener 
   (org.springframework.web.context.ContextLoaderListener) from 
   Spring Framework and it is to be loaded at server startup, by 
   defining this listener in web application deployment descriptor.

3: What are the different beans, those can be created while working
   with Spring's WebApplicationContext ?

Answer :

   Beans such as controller bean, handler mapping bean, view resolver
   bean, locale resolver bean, theme resolver bean, multipart file
   resolver bean (while working with file upload using HTML form), 
   exception hanlder resolver bean etc.

4: What are the different bean scopes those are possible with 
   Spring Framework as of 3.0 version?

Answer :
   
   As of Spring 3.0, bean's scope can fall in any one of these types,
   as follows:
   session scope, singleton scope, prototype scope, request, 
   global session and thread scope, custom defined scope as well.
Are you interested in solving a very interesting Technology Stack while Playing this Game          

Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
4,10
Enter bigger number from above :*
Home >>> Spring Tutorials >>> Interview Question >>> SpringFramework
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
28,24
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed materials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.

By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or 
downloading any materials, you agree to and are bound by the terms of use 
described in this page and Usage Terms and Conditions. 
If you do not agree to all of 
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this 
website in any manner. If you are using the website on behalf of your 
employer, you represent that you are authorized to accept these Terms of Use 
on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any 
of these information, please refer original content/documentation from respective sources. 
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.