Skip to main content

Spring FAQs

What is Spring?
  • Spring is a framework that resolves common problems in JEE architecture. 
  • It is a very light-weight and open source framework because of it's POJO model.
  • It is called as modular framework, since it comes as diffrent modules(we will discuss about these modules in below sections). We can use all modules to develop application or we can use only one module, whichever we required.
  • Spring is called as non-invasive framework. It will not compell a developer to extend any of it's calss or implement any of it's interfaces, where Struts framework forces a developer to extend its Action class. i.e. Struts is said to be invasive frameowrk.
  • Managing business objects and encouraging practices such as programming interfaces rather than classes is a consistent way of using Spring. 
  • Spring addresses all architectural tiers with basic building block by utilizing IoC. 
  • Unique data access abstraction including abstraction of JDBC framework improves the productivity and reduces the errors using Spring. 
  • A flexible and powerful MVC framework which is integrated into the overall IoC container.
  • Due to it's 1) Simplicity  2) Testability & 3)Loose-coupling characterstics made Spring more popular in the J2ee application development.
  • It is very simple frameowrk because of POJO & POJI(Plain Old Java Interface) models.
  • To test a Spring application server is not mandatory, but for Struts we need a server. Spring has it's own container to run the Spring application.
  • Using Spring we can development any kind of application like desktop applications to enterprise level applications.


Explain the different modules in Spring framework.
Spring has the following modules:
  • The Core container module – The fundamental functionality is provided by this module
  • Application context module - Spring is a framework because of this module. This module extends the concept of BeanFactory.
  • AOP module (Aspect Oriented Programming) – This is module is for using aspects of spring based applications.
  • JDBC abstraction and DAO module – To make database code cleanup and to prevent problems at the time of closing database resources, this module is used.
  • O/R mapping integration module (Object/Relational) – This module is used to tie up with ORM tools such as hibernate.
  • Web module – The context for an appropriate web-based application, this module is used
What are the Core container module and Application context module?
Core Container Module: This module is the fundamental module of spring framework. For a spring-based application, BeanFactory is the core. The Spring framework was developed on top of this module. Spring container is made by this module.

Application Context Module: Spring is called a framework because of this module. The concept of BeanFactory is used to extend this module to provide support for internationalization (I18N) messages etc. Enterprise services such as JNDI,EJB integration, remoting and scheduling are supplied by this module.

What is a BeanFactory and XMLBeanFactory?
BeanFactory: Bean factory is a container. It configures, instantiates and manages a set of beans. These beans are collaborated with one another and have dependencies among themselves. The reflection of these dependencies are used in configuring data that is used by BeanFactory.

XMLBeanFactory: XMLBeanFactory is a bean factory that is loaded its beans from an XML file.


What is AOP Alliance?
AOP Alliance: AOP Alliance is an open source project. Promoting adoption of AOP and interoperability among different AOP implementations with the help of interfaces and components that are well defined, are the main goals of AOP Alliance.

Explain the concepts and purpose of Spring configuration file.
A spring configuration file is an XML file which contains the information about classes and describes the process of configuration.

What does a simple spring application contain?
A spring application is like any other Java application. The applications contain classes, each of them perform a specific task with the application. All these classes are configured and introduced to other classes with the help of an XML file. The configuration process is described in the Spring configuration file.

Explain Bean lifecycle in Spring framework.
The bean's definition is found by the spring container from the XML file and instantiates the bean. All the properties specified in the bean definition are populated by spring using dependency injection. The bean's Id is passed to setBeanName() method by the factory, and the factory calls setBeanFactory() is passed to itself, incase the bean implements the BeanFactoryAware interface. The init() method is invoked if specified. If any BeanPostProcessors are associated with the bean, the methods postProcessAfterInitialization() are invoked.


What is bean wiring?
Bean wiring is the process of combining beans with Spring container. The required beans are to be informed to the container and how the container should use dependency injection to tie them together, at the time of wiring the beans.

Explain how to add a bean in spring application.
The id attribute of the bean tag specifies the name of the bean and the fully qualified class name is specified by the class attribute. The following is the fragment of the XML file of spring which illustrates the bean and class attributes.
<bean>
<bean id="bar" class="com.act.SomeAction" singleton="false"/>
</bean>


What are singleton beans and how can you create prototype beans?
All beans defined in the spring framework are singleton beans. The bean tag has an attribute by name 'singleton'. To make the bean singleton, assign 'true' for this attribute. The default value is true, and hence all the beans in spring are by default singleton beans.


What are Inner Beans?
A bean inside another bean is known as Inner Bean. They are created and used on the fly, and can not be used outside the enclosing beans. The Id and scope attributes for inner beans are of no use.

What is Auto wiring? What are different types of Autowire types?
Searching for objects with the same name of object property is called auto wiring in Spring. By default, Spring framework enables the auto wiring.
There are 4 different types of auto wiring. They are
byName
byType
constructor
autodetect


What is meant by Weaving? What are the different points where weaving can be applied?
The process of applying aspects to a target object for creating a new proxy object is referred to as weaving. These aspects are woven at the following specified join points:
Compile Time
Classload Time
Runtime


Explain the different types of AutoProxying.
BeanNameAutoProxyCreator: This proxy is used to identify beans to proxy through a list of names. It checks the matches that are direct, "xxx" and "*xxx".
DefaultAdvisorAutoProxyCreator: This proxy is the implementation of BeanPostProcessor which creates AOP proxies. These AOP proxies are based on BeanFactory's all Candidate Advisors. It is a generic class which does not have a specific code to handle any specific aspects.

Metadata autoproxying: The metadata autoproxy is concerned with the possibility to employ annotations in certain classes, like defining transactions. To configure this type of proxies, the source level metadata interpretation and the bean usage that employs those attributes is done by DefaultAdvisorAutoProxyCreator.


What is DataAccessException?
DataAccessException is an unchecked RuntimeException. These type of exceptions are unforced by users to handle. This exception is used to handle the errors occurring when the details of the database access API in use, such as JDBC.


Explain about PreparedStatementCreator.
To write data to database, PreparedStatementCreator is the most commonly used interface. The interface contains one method by name createPreparedStatement(). Returning a PreparedStatement is need when this interface is implemented. Another interface, SqlProvider is also implemented along with this interface, which has a method getSql() for providing sql strings to JdbcTemplate.


Explain about BatchPreparedStatementSetter.
Updating more than one row at a time, the BatchPreparedStatementSetter is used. This interface has setValues() and getBatchSize() exceptions. The getBatchSize() method is used to specify the number of statements to create.


Explain about RowCallbackHandler and why it is used.
ResultSet is generally used to navigate the records. The spring framework is provided with RowCallbackHandler interface. The method processRow() can be implemented for use of navigation and handling each row. The user can concentrate only on what to do with each row by avoiding navigation process. The processRow() method has the following signature:
void processRow(java.sql.ResultSet rs);


What are the different types of AutoProxying? Explain them [Hint - BeanNameAutoProxyCreator, DefaultAdvisorAutoProxyCreator, Metadata autoproxying]
The types of AutoProxing are :
  • BeanNameAutoProxyCreator
  • DefaultAdvisorAutoProxyCreator
  • Metadata autoproxying
BeanNameAutoProxyCreator: This proxy is used to identify beans to proxy through a list of names. It checks the matches that are direct, "xxx" and "*xxx".

DefaultAdvisorAutoProxyCreator: This proxy is the implementation of BeanPostProcessor which creates AOP proxies. These AOP proxies are based on BeanFactory's all Candidate Advisors. It is a generic class which does not have a specific code to handle any specific aspects.

Metadata autoproxying: The metadata autoproxy is concerned with the possibility to employ annotations in certain classes, like defining transactions. To configure this type of proxies, the source level metadata interpretation and the bean usage that employs those attributes is done by DefaultAdvisorAutoProxyCreator.

Comments

Popular posts from this blog

Asynchronous Vs. Synchronous Communications

Synchronous (One thread):   1 thread -> |<---A---->||<----B---------->||<------C----->| Synchronous (multi-threaded):   thread A -> |<---A---->| \ thread B ------------> ->|<----B---------->| \ thread C ----------------------------------> ->|<------C----->|

WebSphere MQ Interview Questions

What is MQ and what does it do? Ans. MQ stands for MESSAGE QUEUEING. WebSphere MQ allows application programs to use message queuing to participate in message-driven processing. Application programs can communicate across different platforms by using the appropriate message queuing software products. What is Message driven process? Ans . When messages arrive on a queue, they can automatically start an application using triggering. If necessary, the applications can be stopped when the message (or messages) have been processed. What are advantages of the MQ? Ans. 1. Integration. 2. Asynchrony 3. Assured Delivery 4. Scalability. How does it support the Integration? Ans. Because the MQ is independent of the Operating System you use i.e. it may be Windows, Solaris,AIX.It is independent of the protocol (i.e. TCP/IP, LU6.2, SNA, NetBIOS, UDP).It is not required that both the sender and receiver should be running on the same platform What is Asynchrony? Ans. With messag

Advantages & Disadvantages of Synchronous / Asynchronous Communications?

  Asynchronous Communication Advantages: Requests need not be targeted to specific server. Service need not be available when request is made. No blocking, so resources could be freed.  Could use connectionless protocol Disadvantages: Response times are unpredictable. Error handling usually more complex.  Usually requires connection-oriented protocol.  Harder to design apps Synchronous Communication Advantages: Easy to program Outcome is known immediately  Error recovery easier (usually)  Better real-time response (usually) Disadvantages: Service must be up and ready. Requestor blocks, held resources are “tied up”.  Usually requires connection-oriented protocol