Tuesday, 14 March 2017

Explain @RequestMapping annotation.

@RequestMapping annotation is used to map a URL to either an entire class or a particular handler method.

Explain the @Controller annotation.

The @Controller annotation indicates that a particular class serves the role of a controller. Spring does not require you to extend any controller base class or reference the Servlet API.

What is Controller in Spring MVC framework?

Controllers provide access to the application behavior that you typically define through a service interface. Controllers interpret user input and transform it into a model that is represented to the user by the view. Spring implements a controller in a very abstract way, which enables you to create a wide variety of controllers.

What are the advantages of Spring MVC over Struts MVC ?

Following are some of the advantages of Spring MVC over Struts MVC:
  • Spring's MVC is very versatile and flexible based on interfaces but Struts forces Actions and Form object into concrete inheritance.
  • Spring provides both interceptors and controllers, thus helps to factor out common behavior to the handling of many requests.
  • Spring can be configured with different view technologies like Freemarker, JSP, Tiles, Velocity, XLST etc. and also you can create your own custom view mechanism by implementing Spring View interface.
  • In Spring MVC Controllers can be configured using DI (IOC) that makes its testing and integration easy.
  • Web tier of Spring MVC is easy to test than Struts web tier, because of the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
  • Struts force your Controllers to extend a Struts class but Spring doesn't, there are many convenience Controller implementations that you can choose to extend.
  • In Struts, Actions are coupled to the view by defining ActionForwards within a ActionMapping or globally. SpringMVC has HandlerMapping interface to support this functionality.
  • With Struts, validation is usually performed (implemented) in the validate method of an ActionForm. In SpringMVC, validators are business objects that are NOT dependent on the Servlet API which makes these validators to be reused in your business logic before persisting a domain object to a database.

What is WebApplicationContext ?

The WebApplicationContext is an extension of the plain ApplicationContext that has some extra features necessary for web applications. It differs from a normal ApplicationContext in that it is capable of resolving themes, and that it knows which servlet it is associated with.

What is a DispatcherServlet?

The Spring Web MVC framework is designed around a DispatcherServlet that handles all the HTTP requests and responses.

What is Spring MVC framework?

The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

What are ORM's Spring supports ?

Spring supports the following ORM's :
  • Hibernate
  • iBatis
  • JPA (Java Persistence API)
  • TopLink
  • JDO (Java Data Objects)
  • OJB

What are the ways to access Hibernate by using Spring?

There are two ways to access hibernate using spring:
  • Inversion of Control with a Hibernate Template and Callback.
  • Extending HibernateDAOSupport and Applying an AOP Interceptor node.

Which of the above transaction management type is preferable?

Declarative transaction management is preferable over programmatic transaction management though it is less flexible than programmatic transaction management, which allows you to control transactions through your code.

What are the types of the transaction management Spring supports?

Spring supports two types of transaction management:
  • Programmatic transaction management: This means that you have managed the transaction with the help of programming. That gives you extreme flexibility, but it is difficult to maintain.
  • Declarative transaction management: This means you separate transaction management from the business code. You only use annotations or XML based configuration to manage the transactions.

How JdbcTemplate can be used?


With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. JdbcTemplate provides many convenience methods for doing things such as converting database data into primitives or objects, executing prepared and callable statements, and providing custom database error handling.

How JDBC can be used more efficiently in spring framework?

JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate.

What is @AspectJ? based aspect implementation?

@AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations.

What is XML Schema based aspect implementation?

 Aspects are implemented using regular classes along with XML based configuration.

What are the types of advice?

Spring aspects can work with five kinds of advice mentioned below:
  • before: Run advice before the a method execution.
  • after: Run advice after the a method execution regardless of its outcome.
  • after-returning: Run advice after the a method execution only if method completes successfully.
  • after-throwing: Run advice after the a method execution only if method exits by throwing an exception.
  • around: Run advice before and after the advised method is invoked.

What are the different points where weaving can be applied?


Weaving can be done at compile time, load time, or at runtime.

What is Weaving?

Weaving is the process of linking aspects with other application types or objects to create an advised object.

What is Target object?

The object being advised by one or more aspects, this object will always be a proxy object. Also referred to as the advised object.

What is Introduction?

An introduction allows you to add new methods or attributes to existing classes.