Interview Questions.

Spring MVC Interview Questions and Answers For Experienced


Spring MVC Interview Questions and Answers For Experienced

Q1. What is "Spring Framework" ?

Ans: With the two middle concepts of Aspect-Oriented and Dependency Injection, Spring is one of the maximum popular and broadly used Java EE frameworks. Through dependency injection it is able to provide tight coupling among various components. The pass-slicing obligations along with authentication and logging can be furnished thru Spring framework and the aspect-oriented programming may be carried out thru this as properly.

Spring framework is a featured framework that can provide numerous modules and plenty of functions for the precise tasks along with Spring JDBC and Spring MVC. Working with Spring is quite smooth and a amusing activity due to the presence of a number of on-line communities and sources.

Q2. Why Spring Framework is needed?

Ans: Spring framework is needed due to the fact it's miles –

Very Light Weight Container




Q3. What are the blessings of Spring Framework?

Ans: Spring framework offers some of benefits which includes the subsequent:

The direct dependency amongst several components may be decreased through Spring IoC packing containers. They are responsible to create the beans, which can be injected among the additives and to reduce the dependency.

As the enterprise common sense does no longer have any direct dependency at the implementation class of actual aid so it turns into pretty easier to jot down the Unit test instances. The take a look at configurations may be easily written and the configurations can be injected without difficulty for testing functions.

The quantity of boilerplate code is likewise reduced e,g. To open or close the aid or to initialize an JdbcTemplate elegance can also get rid of the boilerplate code required in JDBC programming.

Spring framework can help us in retaining the utility light-weight say e.G if Spring transaction control feature isn't required, then the person needs now not to add that dependency to the undertaking.

Spring framework can aid a number of Java EE framework functions even greater than Spring is always pinnacle of the technology like to put in writing higher naïve android software person can use Spring project for Android. So it is able to be a entire package deal and person need now not have any separate bundle for the work.

Q4. Name a few popular and on the whole used Spring Modules.

Ans: Some critical and in general used Spring modules are:

Spring Context- Used for Dependency Injection

Spring AOP- Used to put in force component-oriented programming

Spring DAO- Used for database operations with the assist of DAO patterns

Spring JDBC- uSed for DataSource and JDBC help

Spring ORM- Used for creating web programs

Spring Web Module- Used to create the net applications

Spring MVC- It is also called Model-View-Controller used to create and put in force the web programs

Q5. What is Spring Bean?

Ans: Any elegance of Spring framework, which is initialized by way of Spring IoC field is referred to as Spring Bean. We can get the Spring Bean instance via Spring Application Context. The life-cycle of Spring Bean may be controlled through Spring IoC container.

Q6. Explain Aspect Oriented Programming.

Ans: Some cross-reducing issues for any business enterprise stage utility like transaction control, records validation, authentication and logging in for various application modules and gadgets are most precious. In case of item-orientated programming such application modularity is carried out via instructions even as in AOP it is executed by Aspects.

Q7. What  are the methods of Bean Life Cycle?

Ans: There are  crucial strategies of Bean life cycle:

Setup – known as when bean is loaded into field

Teardown – referred to as whilst bean is unloaded into box

Q8. What are the features of Spring Framework?

Ans: Spring framework is primarily based on two important principles known as element-oriented programming and dependency injection. Few capabilities of Spring framework are:

Spring framework is light-weight and with little overhead for the developers

The box manager of Spring framework can manage Spring Bean existence cycle and any task unique configurations like JNDI lookup.

It can support JDBC operations, transaction control, exception dealing with and record importing like little configurations either through the use of annotations or with the help of Spring bean configuration report.

This framework may be used to expand the net packages and internet offerings each that can return JSON and XML responses

Through inversion of control and dependency injection standards you may broaden the unbiased additives effortlessly. Through spring containers these additives can be wired easily.

Q9. What is dependency injection?

Ans: Dependency injection is a concept that is carried out via the layout patterns. It can dispose of the hard-coded dependency and might make the utility loosely coupled, maintainable and extendable. The dependency resolution also can be moved from collect time to run time through these design styles. It affords following advantages:

Boilerplate Code Reduction

Separation of Concerns

Easy Unit Testing


Google Guice can also be used for dependency injection and the techniques can be automatic through this. If we want to put in force any extra concept together with dependency injection then Spring is the exceptional choice for that.

Q10. What is the the front controller magnificence of Spring MVC?

Ans: A the front controller is described as “a controller which handles all requests for a Web Application.” DispatcherServlet (honestly a servlet) is the the front controller in Spring MVC that intercepts each request after which dispatches/forwards requests to an appropriate controller.

When a web request is sent to a Spring MVC software, dispatcher servlet first gets the request. Then it organizes the different components configured in Spring’s internet software context (e.G. Actual request handler controller and look at resolvers) or annotations gift inside the controller itself, all needed to handle the request.

Q11. What is Spring MVC Interceptor and the way to use it?

Ans: As you realize about servlet filters that they are able to pre-cope with and post-handle every net request they serve — earlier than and after it’s handled by that servlet. In the similar manner, you can use HandlerInterceptor interface in your spring mvc application to pre-deal with and put up-cope with internet requests which can be dealt with with the aid of Spring MVC controllers. These handlers are generally used to control the model attributes again/submitted they're handed to the perspectives/controllers.

A handler interceptor can be registered for unique URL mappings, so it best intercepts requests mapped to sure URLs. Each handler interceptor have to put in force the HandlerInterceptor interface, which incorporates 3 callback techniques if you want to put in force: preHandle(), postHandle() and afterCompletion().

Problem with HandlerInterceptor interface is that your new magnificence will have to implement all three methods regardless of whether or not it's far needed or now not. To keep away from overriding, you may use HandlerInterceptorAdapter elegance. This magnificence implementsHandlerInterceptor and offer default clean implementations.

Q12. How does Spring MVC provide validation help?

Ans: Spring helps validations mostly into two methods.

Using JSR-303 Annotations and any reference implementation e.G. Hibernate Validator

Using custom implementation of org.Springframework.Validation.Validator interface

Q13. Are Singleton beans thread safe in Spring Framework?

No, singleton beans aren't thread-safe in Spring framework.

Q14. What is the difference between issue and move-reducing problem in Spring AOP?


Concern − Concern is conduct which we need to have in a module of an utility. Concern can be described as a capability we want to put into effect. Issues wherein we are involved define our worries.

Cross-reducing concern − It's a issue which is relevant throughout the software and it impacts the whole utility. E.G. Logging , security and data transfer are the worries which can be wished in nearly each module of an utility, as a result are move-cutting issues.

Q15. How to apply Tomcat JNDI DataSource in Spring Web Application?

Ans: For the use of servlet field configured JNDI DataSource, we want to configure it inside the spring bean configuration file after which inject it to spring beans as dependencies. Then we are able to use it with JdbcTemplate to perform database operations.

< bean id="dataSource" class="org.Springframework.Jndi.JndiObjectFactoryBean">

< property name="jndiName" value="java:comp/env/jdbc/MySQLDB"/>

< /bean>

Q16. What is Bean Factory?

Ans: Bean Factory is center of the spring framework and, it's far a Lightweight box which loads bean definitions and manages your beans.  Beans are configured the use of XML report and manipulate singleton defined bean. It is also accountable for life cycle techniques and injects dependencies. It additionally gets rid of adhoc singletons and factories.

Q17. What are the  extraordinary types of Events of Listeners?

Ans: Following are the specific varieties of activities of listeners:

ContextClosedEvent – This occasion is called when the context is closed.

ContextRefreshedEvent – This event is called when context is initialized or refreshed

RequestHandledEvent – This occasion is called when the web context handles request

Q18. What is the difference between Bean Factory and ApplicationContext?


Application contexts provide a means for resolving textual content messages, along with aid for i18n of these messages.

Application contexts provide a usual manner to load record assets, which include pictures.

Application contexts can publish activities to beans which might be registered as listeners.

Certain operations at the field or beans inside the field, which must be treated in a programmatic style with a bean factory, can be dealt with declaratively in an application context.

The utility context implements MessageSource, an interface used to acquire localized messages, with the real implementation being pluggable.

Q19. What is Controller in Spring MVC framework?

Ans: Controllers offer get right of entry to to the application conduct that you commonly define thru a service interface. Controllers interpret consumer enter and transform it into a version this is represented to the person by the view. Spring implements a controller in a totally summary way, which enables you to create a extensive type of controllers.

Q20. What are the methods to get right of entry to Hibernate through using Spring?

Ans: There are  ways to get entry to hibernate the use of spring −

Inversion of Control with a Hibernate Template and Callback.

Extending HibernateDAOSupport and Applying an AOP Interceptor node.