1. Spring principle The core of the internal is the IOC, dynamic injection, so that an object is created without new, can be automated production, which is actually the use of Java reflection, reflection is actually in the runtime to create, invoke the object, spring is at runtime, with the XML The spring configuration file is used to dynamically create objects and invoke methods in the object. One of the core aspects of spring is AOP, which is the aspect-oriented programming that can be supervised and controlled for a class of objects (that is, calling the module you specify before and after invoking the specific method of such an object) to extend the functionality of a module. These are achieved through the configuration class. Spring purpose: The relationship between objects and objects (modules and modules) is not associated with code, but is managed through the Configuration class description (Spring uses reflection to dynamically assemble objects within these configurations) Keep in mind that spring is a container in which the objects in the container will have these services and functions provided by spring. One of the most classic design patterns used in spring is the template method pattern. (Here I do not introduce, is a very common design pattern), spring configuration is a lot of, it is difficult to remember, but the essence of spring is nothing more than the above two points, the above two points with understanding of the basic master of spring.
Spring AOP and IOC I. IoC (Inversion of control): Inversion of controls 1. IoC: Concept: Control is shifted from the object itself to the container; The container creates an instance from the configuration file and creates a dependency between the individual instances Core: Bean factory; In spring, each instance created by the Bean factory is called a bean Second, AOP (aspect-oriented programming): Aspect-oriented programming 1, the agent of two ways: Static Proxy: Write the proxy class for each specific class; Write a proxy class for an interface; Dynamic Agent: Write a invocationhandler for one aspect, then use the proxy class in the JDK reflector package to dynamically generate the corresponding proxy class for various interfaces 2. Dynamic Agent: Instead of writing the proxy class, the virtual machine generates a class based on the interface implemented by the real object, instantiates a dynamic proxy through the class, injects the real object and equipment into the dynamic agent when the dynamic agent is instantiated, exposes the dynamic agent to the client, and when the client invokes the dynamic proxy method, The dynamic proxy obtains the real object's method according to the reflection of the class, invokes the call method of the equipment, passes the dynamic agent, method, parameter and the Invoke method of the equipment, and the Invoke method does some processing before or after invoking the method. 1, the generation of dynamic proxy class: Java.lang.refect.Proxy 2, equipment must implement Invocationhandler interface implementation Invoke method 3, Reflection What is a class's flyback? The class description allows you to get the parent class, the implemented interface, the inner class, the constructor, the method, the property, and the constructor to instantiate an object, invoke a method, take the property value, and change the value of the property. How to get a class description: Class cls= classes. Class cls= object. GetClass (); Class.forName ("Classpath"); How to get a method and evoke it? Class cls= classes. Constructor cons=cls.getconstructor (New Class[]{string.class}); Object obj=cons.newinstance (New object[]{"AAA"}); Method Method=cls.getmethod ("Methods name", New Class[]{string.class,integer.class}); Method.invoke (obj,new object[]{"AA", New Integer (1)}); 4. What are the three ways to inject spring? Setter Interface Constructor 5, what is the core interface and kernel configuration file of spring? Factorybean: Factory Bean mainly implements Ioc/di ApplicationContext ac=new filexmlapplicationcontext ("Applicationcontext.xml"); Object Obj=ac.getbean ("id value"); 6, Spring Framework 20 Functions 7 modules, respectively, data access/integration (Access integration), Web, AOP, Instrumentation (device), Messaging (message sending), Core Container (Core container), Test
4.1 Core Container The core container contains Spring-core, Spring-beans, Spring-context, Spring-context-support, and spring-expression (spring expression Language,spring expression Voice) these modules. Spring-core and Spring-beans form the most fundamental part of the framework, including control inversion and dependency injection. Beanfactory is a very mature implementation of the factory model. Spring-context is built on Spring-core and Spring-beans, which provides a way to access objects in a framework style, similar to Jndi registration. The ApplicationContext interface is the focus of the spring-context. Spring-context-support provides support for integrating third-party libraries, such as timer quartz. Spring-expression provides a powerful expression language that can query and manipulate objects at run-time. 4.2 AOP and devices The SPRING-AOP module provides an AOP-oriented implementation of tangent-plane programming. For example, developers are allowed to define method interceptors and pointcuts to decouple business logic from system services. The Spring-aspects module provides integration with the ASPECTJ. The Spring-instrument module provides class device support and loader implementations that are used in common application servers. The Spring-instrument-tomcat module contains the spring Tomcat device agent. 4.3 Message sent Spring 4 contains a spring-messaging module that provides an important abstraction of the Spring Integration Project message, Messagechannel, and MessageHandler, which is based on the messaging application. 4.4 Data Access/integration The data access/Integration layer contains JDBC (SPRING-JDBC), ORM (Spring-orm), OXM (SPRING-OXM), JMS (SPRING-JMS), and Transaction (SPRING-TX) modules. 4.5 Web The Web tier contains Spring-web, SPRING-WEBMVC, Spring-websocket, and Spring-webmvc-portlet modules. Among them, Spring-web provides basic features for Web integration, such as file upload functionality. The SPRING-WEBMVC module contains spring's MVC and Rest Web service implementations. The Spring-webmvc-portlet module provides an MVC implementation in a portlet environment. 4.6 Testing The Spring-test module supports spring to build unit and integration tests for JUnit and testng. 5 Why use Spring? Spring's two core functions of IOC and AOP can greatly reduce the coupling of application systems and simplify the development process. Spring Framework technology can work at different levels, such as IOC managing common Pojo objects, and AOP enhances system services and other components (transactional, MVC, JDBC, ORM, and remote invocation, etc.). One of the main features of spring is that it is a non-intrusive service based on the interface. The client binding interface uses Java EE services rather than directly binding services, and the application can use different services (Hibernate, MyBatis, etc.). We can use part of the spring service to our own needs without having to use the full Spring Series project. |
The Spring framework is a layered architecture consisting of 7 well-defined modules. The spring module is built on top of the core container, and the core container defines how the beans are created, configured, and managed, and each module (or component) that makes up the spring framework can exist separately or be implemented in conjunction with one or more modules. The functions of each module are as follows: Core container: The core container provides the basic functionality of the Spring framework. The main component of the core container is Beanfactory, which is the implementation of the factory pattern. The beanfactory uses the inversion of control (IOC) pattern to separate the application's configuration and dependency specifications from the actual application code. Spring Context: The spring context is a configuration file that provides contextual information to the spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internationalization, checksum scheduling. Spring AOP: With the configuration management feature, the Spring AOP module directly integrates aspect-oriented programming capabilities into the spring framework. Therefore, it is easy to enable any object managed by the Spring framework to support AOP. The spring AOP module provides transaction management services for objects in spring-based applications. By using Spring AOP, you can integrate declarative transaction management into your application without relying on EJB components. The Spring dao:jdbc DAO Abstraction Layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the number of exception codes that need to be written (such as opening and closing connections). Spring DAO's JDBC-oriented exception conforms to the common DAO exception hierarchy. The Spring orm:spring Framework inserts several ORM frameworks, providing ORM object-relational tools, including JDO, Hibernate, and IBatis SQL Map. All of these conform to Spring's common transaction and DAO exception hierarchies. Spring Web module: The Web context module is built on top of the application context module and provides the context for Web-based applications. Therefore, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies the process of working with multipart requests and binding request parameters to domain objects. Spring MVC framework: The MVC Framework is a full-featured MVC implementation of building WEB applications. With the policy interface, the MVC framework becomes highly configurable, and MVC accommodates a large number of view technologies, including JSP, Velocity, Tiles, IText, and POI. The functionality of the Spring framework can be used in any Java EE server, and most features are also available in an out-of-management environment. The core point of Spring is to support reusable business and data access objects that are not tied to a particular Java EE service. There is no doubt that such objects can be reused across different Java EE environments (Web or EJB), standalone applications, and test environments. |