Spring interview questions

Spring transactions

1. Transaction management types supported by Spring

Spring supports two types of transaction management:

  • Programmatic transaction management : This means that you manage transactions programmatically, giving you great flexibility, but difficult to maintain.
  • Declarative transaction management: This means that you can separate business code and transaction management, you only need to use annotations and XML configuration to manage transactions

AOP

1. Explain AOP

Aspect-Oriented Programming, or AOP, is a programming technique that allows program modularity to cross-cut concerns, or cross-cut typical divisions of responsibilities, such as logging and transaction management.

2. Aspect

The core of AOP is the aspect, which encapsulates the common behavior of multiple classes into a reusable module that contains a set of APIs to provide cross-cutting functions. For example, a logging module can be called an AOP aspect of logging. Depending on the needs, an application can have several aspects. In Spring AOP, aspects are implemented by classes annotated with @Aspect.

3. In Spring AOP, what is the difference between concerns and cross-cutting concerns?

A concern is the behavior of a module in an application, and a concern may be defined as a function we want to implement.
A crosscutting concern is a concern that is used by the entire application and affects the entire application, such as logging, security, and data transfer, functions that are required by almost every module of the application. So these are all cross-cutting concerns.

4. Connect the dots

A join point represents a location in an application where we can insert an AOP aspect, which is actually where the application executes Spring AOP.

5. Notification

A notification is an action to be done before or after a method is executed, and is actually a code segment that is triggered by the SpringAOP framework when the program is executed.

Spring aspects can apply five types of advice:

  • before : Pre-advice, called before a method is executed.
  • after:  A notification called after the method execution, regardless of whether the method execution was successful or not.
  • after-returning:  A notification that executes only after the method completes successfully.
  • after-throwing:  Advice that is executed when the method throws an exception and exits.
  • around:  Advice called before and after method execution.

6. Cut point

A pointcut is a join point or set of join points at which advice will be executed. Pointcuts can be specified by expressions or by matching.

7. What is introduction? 

Import allows us to add new methods and properties to existing classes.

8. What is the target audience? 

An object informed by one or more aspects. It is usually a proxy object. Also refers to the notified (advised) object.

9. What is a proxy?

A proxy is an object created after notifying the target object. From the client's perspective, the proxy object is the same as the target object.

10. How many different types of automated agents are there?

BeanNameAutoProxyCreator

DefaultAdvisorAutoProxyCreator

Metadata autoproxying

11. What is weaving. What is the difference between weaving applications?

Weaving is the process of linking aspects to other application types or objects or creating a notified object.

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

12. Explain the implementation of aspects based on XML Schema.

In this case, aspects are implemented by regular classes as well as XML-based configuration.

13. Explain annotation-based aspect implementation

In this case (based on the @AspectJ implementation), the style of the aspect declaration involved is the same as that of a normal java class annotated with java5.

Spring MVC

1. What is Spring's MVC framework?

Spring comes with a full-featured MVC framework for building web applications. Spring can be easily integrated with other MVC frameworks, such as Struts. Spring's MVC framework uses inversion of control to clearly isolate business objects and control logic. It also allows declarative binding of request parameters to business objects.

2. DispatcherServlet

Spring's MVC framework is designed around the DispatcherServlet, which handles all HTTP requests and responses.

3. WebApplicationContext

WebApplicationContext inherits ApplicationContext and adds some unique functions necessary for WEB applications. It is different from general ApplicationContext because it can handle themes and find associated servlets.

4. What is a controller in Spring MVC framework?

A controller provides an access to the application's behavior, typically implemented through a service interface. The controller parses user input and converts it into a model that is presented to the user by the view. Spring implements a control layer in a very abstract way, allowing users to create controllers for multiple purposes.

5.  @Controller  annotation

This annotation indicates that this class acts as a controller, and Spring does not require you to inherit from any other controller base class or reference the Servlet API.

6. @RequestMapping annotation

This annotation is used to map a URL to a class or a specific method handler.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325099987&siteId=291194637