What the hell is spring?

Source: Internet
Author: User

Although I have read the book for a while, I can still feel that spring is very abstract.

Introduction to Spring:

leads to:

Dependency Injection . The way is: constructor injection. (+ interface-oriented) for loose coupling.

The behavior of creating collaboration between application components (objects) is called Assembly. Injection is called assembly.

It is common to use XML configuration files.

Aop

Struts2 interceptors are used to filter page requests, and page requests are intercepted by filters before they reach the action.
While AOP is actually a continuation of the GOF design pattern , the design pattern tirelessly pursues the decoupling between the caller and the callee, and is mainly used to solve the crosscutting (crosscut) problem that the OOP and the process methods are not able to solve well.

http://blog.csdn.net/shendl/article/details/526362

Two ways to realize crosscutting concerns
Software Systems,can be seen as consisting of a set of concerns.。 One of the direct business concerns is the straight-cut focus point. and Servicing Direct-cut concerns is a crosscutting concern .。
There are two ways to provide crosscutting concerns, a traditional OOP approach, and a service that provides the same class as the implementation of the straight-cut focus. The other is the latest AOP approach, which provides a aspect aspect (called Advisor Advisor in Spring AOP) to provide services.
The OOP approach is that the business class uses object references and uses "delegation" to invoke methods (services) of the Crosscutting class.
This is the "calling "typeThe service. The business class uses the display code to call the service. This adds the concept of "straight-cut focus" to the business classIrrelevant code, which destroys the encapsulation and adds the business classand the coupling between services
The AOP approach is to provide a aspect aspect, a concept similar to "class" that encapsulates the implementation code for "crosscutting concerns". Andalso provides a "pointcut"。 A pointcut is a collection of "connection points." The starting point is defining the aspect aspectWhich methods of the class are served。 (In fact, the object that needs to serve is integrated into the service side, not the business side of the main call way.) )
There are many ways to implement AOP. The earliest way to do this is to weave in at compile time. This is the way ASPECTJ is used. ASPECTJ's special compilers assemble the code of business classes and aspect aspects to achieve seamless access to services. This way, the business method in the source code is independent of the aspect aspect.
Another typical and ingenious way to implement AOP is to use dynamic proxy simulations. This is now the most popular way. This approach is used by both the JBoss AOP framework and the Spring AOP framework.
Here I describe how the Spring AOP Framework provides a crosscutting focus service. Writing an aspect, this aspect is also a general Pojo class, but it needs to provide an interface.
Then, configure the interface and Pointcut mode using Advisor Advisor (that is, aspect, Aspect + pointcut). When the program runs to the connection point method, build a dynamic proxy class that returns a quiet name for the Java class instead of using the business class directly. This MI class assembles the business class and advise recommendations (that is, the terms of the SPRINGAOP).
Thus, AOP achieves a much better approach to crosscutting concerns than the OOP approach.
In the AOP implementation, I appreciate the AOP that spring AOP implements using dynamic proxy mode. This approach does not require any accessibility tools to develop AOP.
However, one thing to note about developing AOP is that the advice code for Spring AOP can only be called before and after the connection point method, or after the exception is thrown.
This requires that our target method (that is, the connection point, advice to bind it) must be small enough to divide a large method into multiple small methods. This requires "refactoring" technology to help. Of course, this is not a disadvantage, but it is a good habit for you to develop the opportunity. "Method-oriented refactoring!" ”
The proposed technique of AOP is a remarkable achievement. The technology's originator, ASPECTJ, is very clumsy in its own implementation.
The idea of AOP is actually a development of software design ideas, and the discovery of "crosscutting concerns" enables Xerox scientists to create AOP as an "aspect-oriented (crosscutting focus) programming" idea. Also made them sporogenous out of the clumsy freak aspectj. While others are struggling to think of the problem of OOP, the first-line program master, immediately from the idea of AOP to obtain a long-sought solution.
They have turned out the "Dynamic agent Mode" and "Decorator mode" from the design pattern, and elegantly implemented the Pojo-type AOP solution such as JBOSSAOP,SPRINGAOP!

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.