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