Following Spring interview questions are for freshers and experienced users 1 What is a spring? It is the execution of an aspect. Advice is like making your application learn a new trick. They are usually introduced at joinpoints. The default scope of bean is Singleton for Spring framework. Transaction management supported by Spring are : Declarative transaction management.

Author:Tumuro Arahn
Language:English (Spanish)
Published (Last):23 April 2014
PDF File Size:15.1 Mb
ePub File Size:1.61 Mb
Price:Free* [*Free Regsitration Required]

Following Spring interview questions are for freshers and experienced users 1 What is a spring? It is the execution of an aspect. Advice is like making your application learn a new trick. They are usually introduced at joinpoints. The default scope of bean is Singleton for Spring framework. Transaction management supported by Spring are : Declarative transaction management.

Programmatic transaction management. No, singleton beans are not thread-safe in Spring framework. Following are the benefits of Spring framework: Extensive usage of Components Reusability Decoupling Reduces coding effort by using pattern implementations such as singleton, factory, service locator etc. Removal of leaking connections Declarative transaction management Easy to integrate with third party tools and technologies.

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. Bean wiring is the creation of associations between application components that are between the beans in a particular spring container. 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.

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. AOP module is utilized for creating aspects for Spring applications.

It also enables support for metadata programming in Spring. Bean factory interface is used to provide configuration framework for object creation and basic functionality around object management. ApplicationContext allows more than one config files to exist while BeanFactory only permits one.

ApplicationContext can print events to beans registered as listeners. This feature is not supported by BeanFactory. ApplicationContext also provides support for application of lifecycle events, internationalization messages and validation and also provides services like EJB integration, remoting, JNDI access and scheduling.

These features too are not supported by Bean Factory. Autowiring is used to build relationships between the collaborating beans.

Spring container can automatically resolve collaborators for beans. Autowiring has five different modes: no: no autowire byName : Autowiring that can be done by property name byType : property type as autowired constructor: It is similar to byType and it is property is in constructor autodetect : Spring is allowed to select autowiring from byType or constructor 19 How to start using spring?

Following steps needs to be done to start with the Spring: Download Spring and its dependent file from spring's site. Create application context xml to define beans and its dependencies Integrate application context xml with web.

There are two important methods of Bean life cycle: Setup — called when bean is loaded into container Teardown — called when bean is unloaded into container 21 What are the different types of events of Listeners? Following are the different types of events of listeners: ContextClosedEvent — This event is called when the context is closed.

ContextRefreshedEvent — This event is called when context is initialized or refreshed RequestHandledEvent — This event is called when the web context handles request 22 Differentiate between singleton and prototype bean? Singleton means only one bean is defined per object instance while Prototype means one definition to more than one object instances in Spring. Two types of dependency injection are supported by spring framework: Setter Injection Constructor Injection 24 Write about Core container module?

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.

This AOP module is used for spring enabled application. It instructs spring to add annotations to the source code and tell how to apply aspects. The AOP alliance's goal is to define a common set of components and interfaces so as to improve interoperability among different AOP implementations. 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. There are four different types of Auto wire: byName byType constructor autodetect 29 What are the types of the transaction management that is supported by spring?

Following are the types of transaction management that has been supported by spring: declarative programmatically 30 When are declarative and programmatic transaction management used? 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. 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. The different types of events related to listeners are: ContextRefreshedEvent — This gets called when the context is refreshed or initialized. RequestHandledEvent — This gets called when the web context is handling a request.

ContextClosedEvent — This gets called when the context gets closed. 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. 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. 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. Pointcut is used to allow where the advice can be applied. Weaving is used to create new proxy object by applying aspects to target object.

The bean tag has an attribute called 'singleton'. The bean is singleton if its value is 'TRUE', otherwise the bean is a prototype. DAO is used to provide integration of Java database connectivity and Object relational mapping objects.

Autoproxying is used to create proxy automatically for the spring users. 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.

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: Void samplethrow Throw table t Void samplethrow Method m, Object[] o, Object target, Throw tablet 47 What are the various editors used in spring work?

Following are the channels supported by spring version 2. Declarative transaction management has minimum impact on the application code and, therefore, is an idealistic lightweight container. BeanFactory applies the idea of a factory pattern that utilizes IOC to separate the application's dependencies and configuration from the actual code. Scopes of spring bean are Singleton, prototype, request, session and global session. 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 56 What is Inversion of control IOC?

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. 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. What is the drawback of inner bean? 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. Following are the benefits of spring framework: Light weight container when compared to j2EE containers Built in Web MVC framework Creates loosely coupled applications Supports aspect oriented programming like logging, transaction and security Configuration done in XML format which is easy to write and understand 61 What are the types of Advice?

PreparedStatementCreator is one of the most commonly used interfaces for writing data to the database. 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. It is mainly used for debugging. 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. Types of advice are: Before advice: Advice that is executed prior to a joinpoint is called the 'before advice'.


iBATIS Interview Questions & Answers

Finally, the mybatis framework executes sql and maps the result to Java object and return. SQL is written in XML, completely separated from the program code, and the coupling between sql and program code is removed, which facilitates unified management and optimization. There are certain requirements for developers to write SQL statements. It is not an ORM framework. Because MyBatis requires programmers to write Sql statements themselves, but mybatis can flexibly configure the SQL statements to be run through XML or annotation, and map java objects and sql statements. Generate the final execution of sql, and finally map the results of the sql execution to generate a java object. The programmer directly writes the original sql, which can strictly control the execution performance of sql and has high flexibility.


Top 80 Spring MVC Framework Interview Questions & Answers

Hibernate works well when you control the data model, iBatis works well when you need to intergate with an existing database,. Hibernate provides a way to represent database rows as objects so that developers can easily call create update delete methods on them where Ibatis helps developers in mapping SQL queries in the form of XML files these queries can be mapped to a name and parameters can be passed to them. Now these queries can be accesed as Java objects and can be called by passing parameters. These are the few questions that continuously get asked in most of forums.


iBATIS Tutorial

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates. What is ORM?


What is different between Hibernate and iBatis?

I've been playing around with Persistence frameworks lately, after been inspired by a Hibernate , which is a de facto standard is used in lot of places. While Hibernate is certainly an excellent technology, it is not always the right choice. In other words, Hibernate works very well if your data model is well in sync with object model, because ORM solutions like Hibernate map object to tables. One size does not fit all. So this is where I like to use iBatis; as the alternative solution, iBatis maps results sets to objects, so no need to care about table structures. This works very well for stored procedures, works very well for reporting applications, etc,.

Related Articles