There are a great many questions that could come up during a Spring MVC interview. Some of the more common ones will cover topics like defining Spring, listing some features, and explaining dependency injection. Here’s a sample of some questions and answers to expect during a Spring MVC interview. Also, here’s a course that can teach you a lot more about Java.
What is Spring?
Spring is a framework for developing enterprise JavaTM applications. The benefit of using Spring over other frameworks is that it’s open source. This means developers can build reusable code without any vendor lock-in. Another major advantage of Spring is the layered architecture that enables you to select only the components you need while offering a seamless J2EE application development framework.
List the advantages of the Spring framework.
Spring has the following advantages:
- Layered architecture that allows you to use what you need while leaving what you don’t need.
- Spring allows developers to focus on Plain Old Java Object (POJO) Programming. This allows for continuous testing and integration.
- Being an open source, there is no vendor lock-in.
- Dependency injection and inversion of control makes Java Database Connectivity (JDBC) simpler.
List some features of Spring.
Spring manages and contains the configuration and life cycle of application objects.
When it comes to transparency and size, Spring is a lightweight application framework. The lightest version of the Spring framework only takes up 1MB. Additionally, the overhead in terms of processing is similarly minuscule.
Spring utilizes the model-view-controller (MVC) web application framework which is built on the core Spring functionality. This framework accommodates several view technologies such as JSP, Tiles, Velocity, POI, and iText. Additionally, it is highly configurable with the use of strategy interfaces. However, several other frameworks could be easily used in place of the Spring MVC Framework. You can learn more about other MVC frameworks from this course on ASP.NET MVC 4.
Inversion Of Control (IOC):
Spring achieves loose coupling through the use of Inversion of Control. Objects provide their dependencies rather than looking for or creating dependent objects.
A generic abstraction layer is supplied by the Spring framework for the purpose of transaction management. This allows developers to include pluggable transaction managers while making it very easy to separate transactions while avoiding low-level issues. This transaction support is not connected with the J2REE environment. Also, it can be utilized in containerless environments.
Aspect Oriented Programming (AOP):
By separating system services from application business logic, Spring supports aspect oriented programming. This also allows for cohesive deployment of applications.
JDBC Exception Handling:
The Java Database Connectivity (JDBC) abstraction layer of Spring provides a useful exception hierarchy. This makes error handling strategy much easier to develop. Additionally, Spring offers great integration services with JDO, iBATIS, and Hibernate.
What is Dependency Injection (AKA IOC)?
Dependency Injection or Inversion of Control (IOC), at the most basic level, allows you to describe how objects should be created rather than creating them directly. That is, you describe the services that are needed by different components using a configuration file rather than directly connecting these components and services in code. In the case of the Spring framework, these services and components are then connected by the IOC container.
For example, objects are given their dependencies when they are created by an external process that manages each object within a system. In other words, the dependencies are inserted into objects. This is contrary from the way dependencies are handled in other frameworks, which is why the term inversion of control was coined. This signifies an inversion of responsibility for creating references to dependencies within objects. Here’s a course that can teach you more about the basics of Spring 3.2 Framework.
List some different types of Dependency Injection (IOC)
The three (3) types of dependency injection, or IOC, are:
- Setter Injection (used by Spring): JavaBeans properties are used to assign dependencies.
- Interface Injection (used by Avalon): An interface is used for injection.
- Constructor Injection (used by Spring, Pico container, and others): Constructor parameters are used to provide dependencies.
It’s important to note that Spring only supports Setter Injection and Constructor Injection.