Wirecard Frequently Asked Spring MVC Interview Questions Answers

Enlist and explain the main methods associated with the Resource interface.

Methods associated with resource interface are as follows:

1. getInputStream() : It locates and opens the resource, returning an InputStream to read from the resource.

2. exists() : Returns a boolean which indicates whether this resource actually exists in physical form.

3. isOpen() : Returns a boolean which indicates whether this resource represents a handle with an open stream.

4. getDescription() : Returns a description for this resource, which is used for error output when working with the resource.

Give some examples where property editing is used in spring.

Following are the examples for property editing in spring :

1. Setting of properties on beans is done by using PropertyEditors. To mention java.lang.string as the value for a property of some bean you're declaring in XML file, Spring will use the ClassEditor to try resolving the parameter to a Class object.

2. Passing HTTP request parameters in Spring's MVC framework can be done using all kinds of PropertyEditors that can be manually bind in all subclasses of the CommandController.
Explain the main AOP concepts and terminology.

The main AOP concepts are as follows:

1. Aspect : A modularization of a concern that cuts through multiple classes.

2. Join point : It is a point during which the execution of a programming, such as the execution of method or handling of an exception.

3. Advice : An action taken by an aspect for a particular join point.

4. Point cut : A predicate that is matched to join points.

5. Introduction : Declaration of additional methods or fields on behalf of a type.

6. Target object : Object which is advised by one or more aspects.

7. AOP proxy : An object which is created by AOP framework for implementing the aspect contracts.

8. Weaving : Linking of aspects with other application types or objects to create an advised object.
Wirecard Frequently Asked Spring MVC Interview Questions Answers
Wirecard Frequently Asked Spring MVC Interview Questions Answers

Difference between @Component, @Controller, @Repository & @Service annotations?

1) The @Component annotation marks a java class as a bean so the component-scanning mechanism of spring can pick it up and pull it into the application context. To use this annotation, apply it over class as below:

@Component
public class EmployeeDAOImpl implements EmployeeDAO {
    ...
}
2) The @Repository annotation is a specialization of the @Component annotation with similar use and functionality. In addition to importing the DAOs into the DI container, it also makes the unchecked exceptions (thrown from DAO methods) eligible for translation into Spring DataAccessException.

3) The @Service annotation is also a specialization of the component annotation. It doesn’t currently provide any additional behavior over the @Component annotation, but it’s a good idea to use @Service over @Component in service-layer classes because it specifies intent better.

4) @Controller annotation marks a class as a Spring Web MVC controller. It too is a @Component specialization, so beans marked with it are automatically imported into the DI container. When you add the @Controller annotation to a class, you can use another annotation i.e. @RequestMapping; to map URLs to instance methods of a class.

What is view Resolver pattern ? how it work in Spring MVC?

Spring Framework Interview Question Answers | Spring MVC FAQView Resolver pattern is a J2EE pattern which allows a web application to dynamically choose it's view technology e.g. HTML, JSP, Tapestry, JSF, XSLT or any other view technology. In this pattern, View resolver holds mapping of different views, controller return name of the view, which is then passed to View Resolver for selecting an appropriate view. Spring MVC framework supplies inbuilt view resolver for selecting views.

What is Spring Security ?

Spring security is a project under spring framework umbrella, which provides support for security requirements of enterprise Java projects. Spring Security formerly known as aegis security provides out of box support for creating login screen, remember me cookie support, securing URL, authentication provider to authenticate the user from the database, LDAP and in memory, concurrent active session management support and much more. In order to use Spring security in a Spring MVC based project, you need to include spring-security.jar and configure it in application-Context-security.XML file, you can name it whatever you want, but make sure to supply this to ContextLoaderListener, which is responsible for creating Spring context and initializing dispatcher servlet.

How do you control concurrent Session on Java web application using Spring Security?

You can use Spring Security to control a number of active session in Java web application. Spring security framework provides this feature out of the box and when enabled , a user can only have one active session at a time.

What types of dependency injection is supported by Spring Framework? When do you use Setter and Constructor Injection, pros and cons?

There are 2 types of dependency injection supported by Spring, constructor based injection, and setter-based injection. Both types have their own advantages and disadvantages, you should use Constructor injection when object's dependencies are not optional and they must be initialized with their dependencies. Also use constructor injection if the order of initialization or dependency matters because in Setter based injection you cannot impose any order. Use setter injection when dependencies are optional.

How do Spring resolves view returned by ModelAndView class ?

Some Spring MVC questions are tricky e.g. Struts and Spring integration and can be only answered by experienced Java program with 2 to 4-year experience in Spring MVC framework.

What are different implementations of View interface you have used in Spring MVC?

ULBased View e.g. JSP , JSTLView,

How to escape HTML special characters using Spring MVC?

There are some methods in Spring tag library, can't remember now.

What does the ViewResolver class?

ViewResolver is an interface to be implemented by objects that can resolve views by name. There are plenty of ways using which you can resolve view names. These ways are supported by various in-built implementations of this interface. Most commonly used implementation is InternalResourceViewResolver class. It defines prefix and suffix properties to resolve the view component.

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>
So with above view resolver configuration, if controller method return “login” string, then the “/WEB-INF/views/login.jsp” file will be searched and rendered.

What is a MultipartResolver and when its used?

Spring comes with MultipartResolver to handle file upload in web application. There are two concrete implementations included in Spring:

CommonsMultipartResolver for Jakarta Commons FileUpload
StandardServletMultipartResolver for Servlet 3.0 Part API
To define an implementation, create a bean with the id “multipartResolver” in a DispatcherServlet’s application context. Such a resolver gets applied to all requests handled by that DispatcherServlet.

If a DispatcherServlet detects a multipart request, it will resolve it via the configured MultipartResolver and pass on a wrapped HttpServletRequest. Controllers can then cast their given request to the MultipartHttpServletRequest interface, which permits access to any MultipartFiles.

How does Spring MVC provide validation support?

Spring supports validations primarily into two ways.

Using JSR-303 Annotations and any reference implementation e.g. Hibernate Validator
Using custom implementation of org.springframework.validation.Validator interface.

Post a Comment

Previous Post Next Post