Five Java-related face questions per day (8)--spring

Source: Internet
Author: User

First of all, if there is a big God in front-end development or ready to engage in front-end development of the small partners do not want to see this blog I read this text welcome to add my QQ: "845415745." soon into the Society of the Novice college students have about the front-end development of professional problems want to ask or discuss together, thank you.

Today is still the same as five a day

1 What are the advantages of using the spring framework?

For:
Light Weight: Spring is lightweight and the major version number is approximately 2MB.
Control Inversion: Spring is loosely coupled through control inversion, and objects are given their dependencies. Instead of creating or finding dependent objects.
Tangent-oriented programming (AOP): Spring supports tangent-oriented programming and separates application business logic from system services.
Container: Spring includes and manages the life cycle and configuration of objects in your app.
MVC framework: Spring's web framework is a well-designed framework. is a very good alternative to the web framework.


Transaction Management: Spring provides a continuous transaction management interface that can be extended up to the local transaction down to the global transaction (JTA).
Exception Handling: Spring provides a handy API to put detailed technology-related exceptions (for example, by JDBC. Hibernate or jdo thrown) into a consistent unchecked exception.

2. What is the concept of AOP and Ioc/di and how is it applied in spring?

For:
aop,aspect oriented program. Programming for (aspect) facets;
Ioc,invert of Control. Control reversal.

An instance of an object is generated by the container itself,
That is, programming with the interface, not appearing newkeyword in the program, but using the interface to name the reference.
Then, in some way, an instance of an implementation class of an interface is injected into a reference. This allows the interface to be loosely coupled with the detailed implementation class.
The relationship between the container control program (through XML configuration), rather than the traditional implementation of the code directly manipulated by the program,
Dependency injection, which is an aspect of the IOC, is a common concept. It has many interpretations.

The idea is that you don't have to create objects. It is only necessary to describe how it was created.

You don't assemble your components and services directly in the code, but in the configuration file, describe what services are required for which components. Then a container (the IOC container) is responsible for assembling them together. Simply say it. The IOC is actually a dependency injection. (When you reference a class object in a Class object.) We are usually directly through new contructor).

Control is transferred from the application code to the external container, and the transfer of control is called reversal.
The AOP approach is very similar to filter. is to insert very many other code that needs to be executed in the middle of a normal business flow, like a slice.
For example, log in to log in before entering the login page, not often used, especially in connection with the database, or with the payment of the program will certainly be in each
Insert the log before the step.


Aspect-oriented programming, that is, AOP. is a programming technique that agrees that program apes modularize behavior (such as logging and transaction management) of crosscutting concerns or crosscutting typical lines of responsibility.
The core structure of AOP is the facet, which encapsulates behaviors that affect multiple classes into reusable modules.
AOP Advice (AOP notifications) are divided into:
Pre-notification post notification exception notification around notification

There are several ways to 3:spring things? What are the benefits of the transaction management of the spring framework? What type of transaction management are you more inclined to use? Talk about the isolation level and propagation behavior of spring things?

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 from transaction management, and you only need annotations and XML configuration to manage transactions.
It is a different transaction API such as Jta,jdbc,hibernate. JPA and JDO. Provides a constant programming pattern.


It provides a simple set of APIs for programmatic transaction management rather than some complex transactional APIs such as
It supports declarative transaction management.
It is very well integrated with spring's various data access abstraction layers.
Most spring framework users choose declarative transaction management, because it has the least impact on code,
Thus more in line with the idea of a non-intrusive lightweight container. Declarative transaction management is preferable to programmatic transaction management.
Although there is less flexibility than programmatic transaction management, which allows you to control transactions through code.

isolation level of the transaction:
The database system provides 4 levels of transaction isolation. In these 4 isolation levels. The serializable has the highest isolation level. Read UNCOMMITTED has the lowest isolation level.
· READ UNCOMMITTED reading uncommitted data; (dirty reads will occur)
· Read Committed reading submitted data;
· Repeatable read can be repeated;
The propagation properties of a transaction include:
· The required business method needs to be executed in a transaction, assuming that a method executes in a transaction. Then increase to that transaction. Otherwise, create a new transaction for yourself. The propagation attribute is used for the 80% method.
· Not-supported RequiresNew Mandatoky Supports Never Nested

4: Explains the Bean's life cycle in the spring framework and several scopes supported by spring.

For:

    • The spring container reads the bean definition from the XML file and instantiates the bean.

      Spring populates all properties with the Bean's definition.

    • Suppose the bean implements the Beannameaware interface. Spring passes the Bean's ID to the Setbeanname method.
    • Assuming that the bean implements the Beanfactoryaware interface, spring passes beanfactory to the Setbeanfactory method.

    • Assume that there are no beanpostprocessors associated with the bean. Spring calls them within the Postprocesserbeforeinitialization () method.

    • Assuming the bean implementation is Intializingbean, call its Afterpropertyset method,
    • Suppose the Bean declares the initialization method. Call this initialization method.
    • Assuming there are beanpostprocessors and bean associations, the Postprocessafterinitialization () method of these beans will be called.

    • Assuming the bean implements Disposablebean, it calls the Destroy () method.
      The spring framework supports the following five types of bean scopes:
singleton : bean在每一个Spring ioc 容器中仅仅有一个实例。prototype:一个bean的定义能够有多个实例。

request:每次http请求都会创建一个bean,该作用域仅在基于web的Spring ApplicationContext情形下有效。session:在一个HTTP Session中,一个bean定义相应一个实例。该作用域仅在基于web的Spring ApplicationContext情形下有效。global-session:在一个全局的HTTP Session中,一个bean定义相应一个实例。该作用域仅在基于web的Spring ApplicationContext情形下有效。

5: Tangent-oriented principle

For:
Object-oriented programming focuses on core business, while aspect-oriented programming mainly focuses on some non-core business, but also the necessary auxiliary function.
is to extract the code that is not the core business that should be handled, and encapsulate it into a modular format. To handle those additional feature codes, such as logs. Transaction. Security verification) We understand the role of this module as a facet, telling us that it is a functional module. We can think of it as a facet. To put it bluntly, we write a class. Write a method in this class that deals with the same effect in the core business.
We also need to know two keyword:
 connection point (Joinpoint), a simple understanding is the method defined in the tangent module. Is the method in the definition class above.
 pointcut (Pointcut). Is the collection of connection points, which is a collection of a set of methods. The next few are more understandable. The target object is the core business to be processed. The agent is easier to understand. Get an agent to finish this task.
About AOP programming can follow my three blog posts about agents:
The static proxy of Spring AOP learning
Spring AOP Learning Java JDK Dynamic Agent
Spring AOP Learning cjlib Dynamic Agent

Five Java-related face questions per day (8)--spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.