Ans: Spring is set to be a framework which helps Java programmer for development of code and it provides IOC container, Dependency Injector, MVC flow and many other APIs for the java programmer.
Ans: It is the execution of an aspect. Advice is like making your application learn a new trick. They are usually introduced at joinpoints.
Ans: The default scope of bean is Singleton for Spring framework.
Ans: Transaction management supported by Spring are :
Ans: No, singleton beans are not thread-safe in Spring framework.
Ans: Following are the benefits of Spring framework:
Ans: Bean Factory is core of the spring framework and, it is a Lightweight container which loads bean definitions and manages your beans. Beans are configured using XML file and manage singleton defined bean. It is also responsible for life cycle methods and injects dependencies. It also removes adhoc singletons and factories.
Ans: Bean wiring is the creation of associations between application components that are between the beans in a particular spring container.
Ans: A Spring MVC is a single shared controller instance and it is used to handle request type controllers, interceptors which run in the IoC container. It also allows multiple Dispatcher Servlets which can share application context interface but not class based interface.
Ans: Spring framework is needed because it is –
Ans:
Ans: The RowCallbackHandler is called for each row in ResultSet and is used to read values from the ResultSet.
Ans: This is a very important module and supplies various necessary services like EJB integration, remoting, JNDI access and scheduling. It transforms spring into a framework. It also broadens the idea of BeanFactory by application of lifecycle events, providing support for internationalization messages and validation.
Ans: AOP module is utilized for creating aspects for Spring applications. It also enables support for metadata programming in Spring.
Ans: Bean factory interface is used to provide configuration framework for object creation and basic functionality around object management.
Ans:
Ans: Autowiring is used to build relationships between the collaborating beans. Spring container can automatically resolve collaborators for beans.
Ans: Autowiring has five different modes:
Ans: Following steps needs to be done to start with the Spring:
Ans: There are two important methods of Bean life cycle:
Ans: Following are the different types of events of listeners:
Ans: Singleton means only one bean is defined per object instance while Prototype means one definition to more than one object instances in Spring.
Ans: Two types of dependency injection are supported by spring framework:
Ans: Core container module is responsible for the basic functionality of the spring framework. The whole Spring framework is built with this module as a base.
Ans: This AOP module is used for spring enabled application. Support has been provided AOP alliance to ensure the interoperability between spring and other AOP frameworks.
It instructs spring to add annotations to the source code and tell how to apply aspects.
Ans: AOP alliance is an open-source project which is aimed at promoting adoption of AOP. The AOP alliance’s goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations.
Ans: Spring configuration file is an XML file and it contains class information. It also describes how these classes are configured and interact with each other.
Ans: There are four different types of Auto wire:
Ans: Following are the two types of transaction management that has been supported by spring:
Ans: When only a small amount of transactional operations is there, it is advised to use Programmatic transaction management. But if there is a big amount of transactional operations to be taken care of, declarative transaction management is preferred.
Ans: IOC (Inversion of Control pattern) is also known as dependency injection. IOC directs the programmers to depict how to create objects instead of actually creating them. But in this design pattern, this control has been given to assembler and assembler will instantiate required class if needed.
Ans: The different types of events related to listeners are:
Ans: Aspect is also called as logging which is required throughout the application. Logging or aspect is a cross cutting functionality in an application using AOP.
Ans: The point where an aspect can be introduced in the application is known as a joinpoint. This point could be a field being modified, a method being called or even an exception being thrown. At these points, the new aspect’s code can be added to introduce a new behavior to the application.
Aspect code can be inserted at this point into normal flow of application to change the current behavior.
Ans: Advice will tell application on new behavior and it is the implementation of an aspect. It is inserted into an application at the joinpoint.
Advice is the implementation of an aspect. It is something like telling your application of a new behavior. Generally, the advice is inserted into an application at joinpoints.
Ans: Pointcut is used to allow where the advice can be applied.
Ans: Weaving is used to create new proxy object by applying aspects to target object.
Ans: Singleton Bean – Single bean definition to a single object instance per Spring IOC container
Prototype Bean – Single bean definition to any number of object instances per Spring IOC Container
Ans: Following are the points where weaving can be applied:
Ans: Following are the different types of AutoProxying:
Ans: The bean tag has an attribute called ‘singleton’. The bean is singleton if its value is ‘TRUE’, otherwise the bean is a prototype.
Ans: DAO is used to provide integration of Java database connectivity and Object relational mapping objects. DAO is spring framework provides connection for JDBC, hibernate, JDO, JPA, Common client interface and Oracle.
Ans: Autoproxying is used to create proxy automatically for the spring users. It provides following two classes to support this automatic proxy creation:
Ans: Metadata Autoproxying can be performed inspiring which can be driven by metadata. This is determined by source level attributes and keeps metadata inside the source code.
This maintains metadata in one place and mainly used for declarative transaction support.
Ans: ‘Throws Advice’ define the behavior when an exception occurs. It is an interface and it has no methods which need to be implemented.
A class that implements this interface should have method with this signature:
Ans: The various custom editors provided by the Spring Framework are:
Ans: Following are the advantages of spring framework:
Ans: Hibernate can be accessed in the following two ways:
Ans: Following are the channels supported by spring version 2.0:
Ans: Declarative transaction management has minimum impact on the application code and, therefore, is an idealistic lightweight container.
Ans: BeanFactory applies the idea of a factory pattern that utilizes IOC to separate the application’s dependencies and configuration from the actual code.
Ans: Scopes of spring bean are Singleton, prototype, request, session and global session.
Ans: There are two ways to access hibernate using spring:
Ans: There are two options for struts application that can be integrated with spring:
Configuration of Spring to manage beans using ContextLoader plugin and set their dependencies in a spring context file
Grab spring managed beans explicitly using agetwebapplicationcontext()
Ans: Inversion of Control (IOC) is also called as dependency Injection which is nothingbut a design pattern that gives control to the assembler of classes. In general, class will instantiate another class if required.
But in this design pattern, this control has been to given to assembler and assembler will instantiate required class if needed.
Ans: The major benefits of dependency injection or IOC are that it reduces the amount of coding required for the application. This allows the testing of the application to be done quickly and easily as no JNDI lookup mechanism or singletons are required. IOC containers also support lazy loading and eager installation of services.
Ans: If a bean element is directly embedded in a property tag while wiring beans, then the bean is called Inner Bean. Its drawback is that it cannot be reprocessed.
Ans: There are three types of Injection in spring:
Ans: Following are the benefits of spring framework:
Ans: There are five types of Advice:
Ans: PreparedStatementCreator is one of the most commonly used interfaces for writing data to the database. createPreparedStatement() is a method that can be used to create and return PreparedStatement from the Connection argument, and exception handling is automatically taken care of. When this interface is implemented, a different interface SqlProvider can also be implemented which has a method called getSql(). This method is useful for providing sql strings to the JdbcTemplate. It does not handle SQLExceptions.
Ans: SQLProvider has only one method called getSql()and it is implemented using PreparedStatementCreator implementers. It is mainly used for debugging.
Ans: BatchPreparedStatementSetter is used to update more than a single row in one go, they can use BatchPreparedStatementSetter. This interface provides two methods they are
Ans: If JDBC is used with the template class called JdbcTemplate, it gives a better performance.
Ans: In spring DAO classes only throws SQLException.
Ans: The database code can be kept clean and simple by using the DAO module. This helps in preventing problems that rise because of poor handling of closures of database resources. Also, the DAO module utilizes the AOP module to enable objects in the Spring application to use transaction management services.
Ans: They are:
1
2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN">
<beans>
<bean id="foo"/>
<bean id="bar"/>
</beans> |
The bean tag has an ID attribute which stores the bean name and a class attributes which specifies the full class name.
Ans: Object/relational mapping (ORM) tool is supported by Spring over straight JDBC by implementing the ORM module. Spring can join various important ORM frameworks, including JDO, iBATIS SQL Maps and Hibernate.
Ans: Types of advice are:
Ans: The web module enables the creation of a web application without XML. The web.xml file needs to be configured for using the web module.
Ans: DataAccessException is a RuntimeException. It is an Unchecked Exception. The user cannot be forced to handle these kinds of exceptions.
Ans: Spring includes several applications of Bean factory. Out of these, org.springframework.beans.factory.xml.XmlBeanFactory is a very important one. It loads the beans on the basis of the definitions stored in an XML file. For the creation of an XmlBeanFactory, a java.io.InputStream is passed to the constructor. The InputStream provides the XML to the factory. For example, for retrieval of the bean, the getBean() method is called by passing the name of the desired bean.
1 | MyBean helloBean = (MyBean) factory.getBean("helloBean"); |
Ans: It is the DataAccessException given by org.springframework.dao.DataAccessException
Ans: The different types of loC are: –
Out of these three, only construction and setter are being used in Spring.
Ans: All in all, two bean lifecycle methods are there. The first method is the setup method which is called during the loading of the bean into the container. The second is when the bean is unloaded from the container, and this method is called the teardown.
Ans: The tag, bean, has two useful attributes which can be used to define special initialization and destruction methods.
For Example, two new methods forSetup and forTeardown can be added to the Foo class in the following way:
1
2 3 4 5 |
<beans>
<bean id="bar" init-method=”forSetup” destroy=”forTeardown”/>
</beans> |
Ans: A target is the class that is advised. This class can either be a class to which we want to add a special behavior to or a third party class. The target class is free to center on its major concern using the AOP concepts, regardless of any advice that is being applied.
Ans: The term proxy refers to an object which is produced the application of an advice to the target object.
Ans: Cross cutting concern: It is a concern which is applicable throughout the application and it affects the entire application. E.g Security, logging and data transfer are the concerns which are needed in almost every module of an application.