Wednesday, May 11, 2016

Spring FAQ

1. What is Spring?

Spring framework as “an application framework and inversion of control container for the Java platform". Spring is essentially a lightweight, integrated framework that can be used for developing enterprise applications in java.

2. Name the different modules of the Spring framework.

The Spring framework has the following modules:
  • JDBC module
  • ORM module
  • OXM module
  • JMS module
  • Transaction module
  • Web module
  • Web-Servlet module
  • Web-Struts module
  • Web-Portlet module

4. Explain Dependency Injection in the context of Spring framework.

Dependency Injection is a design pattern that allows users to remove hard-coded dependencies and ensure that the application is loosely coupled, extendable and maintainable. The dependency injection design pattern is used to move the dependency resolution from compile to runtime.

7. List some of the important annotations in annotation-based Spring configuration.

  • @Required @Autowired @Qualifier @Resource@PostConstruct @PreDestroy

8. In the context of Spring framework, explain aspect-oriented programming.

Aspect Oriented Programming basically breaks down program logic into smaller chunks called “concerns”. The functions across multiple points of an application are called cross-cutting concerns and these operate independent of the application’s core business logic. Some of the important Aspects in the context of Spring framework are; logging, auditing, caching and declarative transaction.

10. List the different Scopes of Spring bean.

There are five Scopes defined in Spring beans. They are:
  • singleton
  • prototype
  • request
  • session
  • global-session

13. What are the different types of Spring bean autowiring?

  • autowirebyName 
  • autowirebyType
  • autowire by constructor
  • autowire with @Autowired and @Qualifier annotations

14. Explain the role of DispatcherServlet and ContextLoaderListener.

DispatcherServlet is basically the front controller in the Spring MVC application as it loads the spring bean configuration file and initializes all the beans that have been configured. If annotations are enabled, it also scans the packages to configure any bean annotated with @Component, @Controller, @Repository or @Service annotations.
ContextLoaderListener, on the other hand, is the listener to start up and shut down the WebApplicationContext in Spring root. Some of its important functions includes tying up the lifecycle of ApplicationContext to the lifecycle of the ServletContext and automating the creation of ApplicationContext.

15. Explain the role of InternalResourceViewResolver and MultipartResolver.

InternalResourceViewResolver is one of the implementations of the ViewResolver interface that allows you to view the page directory and suffix locations through the bean properties.
MultipartResolver, on the other hand is the interface that is used for uploading files
– CommonsMultipartResolver and StandardServletMultipartResolver are two implementations provided that are provided by the Spring framework for file uploading.

16. How do you create ApplicationContext in a standalone Java program?

We can do this in three ways:
  • AnnotationConfigApplicationContext: If we are using annotations for configuration, then we can use this to initialize the container and get the bean objects.
  • ClassPathXmlApplicationContext: If we have spring bean configuration xml file in the Java application, then we can use this class to load the file and retrieve the container object.
  • FileSystemXmlApplicationContext: This is quite similar to ClassPathXmlApplicationContext except for the fact that the xml configuration file can be loaded from any location in the file system.

17. Explain the uses of the JDBC template in Spring.

Spring simplifies database access handling with the Spring JDBC Template.
The Spring JDBC Template has many advantages compared to the standard JDBC:
  • The Spring JDBC template automatically cleans up the resources; like releasing database connections.
  • The Spring JDBC template converts the standard JDBC SQLExceptions into RuntimeExceptions. This ensures faster response time to identify and eliminate errors.

18. What kinds of transaction management support does Spring offer?

  • Programmatic Transaction Management: for operations with lesser transaction, and
  • Declarative Transaction Management: for larger number of transactions.

19. Explain the difference between Concern and Cross-cutting concern in Spring AOP.

Simply put, Concern is the desired behavior in a module of an application. It is the core functionality the programmer wants to implement.
Cross-cutting concern, on the other hand, is the Concern that is applicable across the entire application. Examples of Cross-cutting concern would be security, data transfer, logging etc.

20. Explain Advice, in the context of Spring.

Advice is an implementation of Aspect. It is inserted into an application at Join Points. There are different types of Advice including “around,” “before” and “after”.

21. What is a JoinPoint, in the context of Spring?

A JoinPoint is an opportunity within the code to which we can apply an Aspect. In Spring programming, a Join Point always represents a method execution.

22. What kind of JoinPoints does Spring support?

The Spring framework supports method executionJoinPoints.

23. What is a Pointcut?

Pointcut is a predicate that matches join points. A point cut defines at what JoinPoints an advice should be applied.

24. What is a Target Object?

Target Object is a proxy object that is advised by one or more aspects.

25. What is Weaving?

It is the process of linking the Aspect with other applications.

No comments:

Post a Comment