What is Spring?
Explain the different modules in Spring framework.
What is a BeanFactory and XMLBeanFactory?
What is AOP Alliance?
Explain the concepts and purpose of Spring configuration file.
What does a simple spring application contain?
Explain Bean lifecycle in Spring framework.
What is bean wiring?
Explain how to add a bean in spring application.
What are singleton beans and how can you create prototype beans?
What are Inner Beans?
What is Auto wiring? What are different types of Autowire types?
What is meant by Weaving? What are the different points where weaving can be applied?
Explain the different types of AutoProxying.
What is DataAccessException?
Explain about PreparedStatementCreator.
Explain about BatchPreparedStatementSetter.
Explain about RowCallbackHandler and why it is used.
What are the different types of AutoProxying? Explain them [Hint - BeanNameAutoProxyCreator, DefaultAdvisorAutoProxyCreator, Metadata autoproxying]
- 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.
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
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.
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.
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.
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.
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.
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>
<bean id="bar" class="com.act.SomeAction" singleton="false"/>
</bean>
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.
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
byType
constructor
autodetect
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
Classload Time
Runtime
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.
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.
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.
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.
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);
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
Post a Comment