spring module
First, what is the dependency injection, what is the inversion of control (the IOC), there are several injection dependent manner in the spring
Inversion of control (Inversion of Control, abbreviated as the IoC), one design principles of object oriented programming, can be used to reduce the degree of coupling between the computer code.
The right to call the object manipulated by the program code to the container, to achieve and manage objects assembled components through the container. The so-called "inversion of control" that is, the transfer of control of the Component Object, transferred from the program code itself to the outside of the container, the container to create objects and manage dependencies between objects.
The most common method is called dependency injection (Dependency Injection, referred to as DI), there is a way called "dependent lookup" (Dependency Lookup)
Dependency Injection (DI) is a spring core, called a reverse dependency injection control early, because the spring loaded class active task dependencies of the object to be responsible for the container, while the class only need to use these classes on the line,
Class need not concern specific implementation dependent objects to achieve a loose coupling, to facilitate module testing.
Injection method:
Constructor injection.
set injection.
Interface injection.
Two, Spring configuration bean There are several ways
XML-based configuration
Annotation-based configuration
Java-based configuration
three. spring in a bean life cycle.
Create a bean, first need to be instantiated, and then set the attribute value to set the bean name, and then through a series of system initialization, using the bean can be provided, for destructor operation destroys the bean when the container is closed.
This is a simple bean beanFactory assembly process, if the bean referenced in the context of the spring, will be in the initialization process, and then call it setApplicationContext method.
Four, spring bean role.
The default spring scope of the bean in a single embodiment, singleton.
the prototype, and singleton contrary, the prototype of the embodiment is multiple, he requested to create an instance of each separate bean
Fifth, automatic assembly of several ways spring
1.NO, spring default fitting manner, in this embodiment, spring assembly function is automatically turned off.
2.byName: spring will automatically find the same instance of the object name beanId bean configuration and automatically injected, if not the error.
3, .byType: spring automatically finds an object type with the same configuration instance bean and automatically injected, if no error is
4.constructor: Similar patterns byType automatic assembly and constructors, but only applies to bean same argument to the constructor, if consistent with the bean constructor parameter type is not found in the container, it will throw an exception.
5.autodetect: spring automatically configured automatic assembly or test byType autowire
Sixth, talk about the difference between BeanFactory and applicationContext
beanfactory is the bottom of the interface to instantiate, he could only provide a simple injection function, applicationContext is more of a business-class service provided
The difference is: where is the delay in loading BeanFactory, that know the code to call the getBean, bean will be spring assembly,
The applicationContext the start of the project, it will load all the bean. Of course, it applicationContext it can be configured as lazy-init = true Bean Bean delay to allow instantiation.
Examples of the advantages and disadvantages of delayed
Advantages: less resource-intensive start-up, for a relatively large footprint applications that have comparative advantages.
Cons: speed is relatively slow. And it is possible null pointer exception error occurs, and when the project started earlier to load the bean convenient to find out configuration problems bean.
When the web application is recommended to start to put all the bean gave loaded.
Seven .spring way to manage affairs
Programmatic transaction
Declarative transaction
Declarative transaction which has been divided into two categories.
Xml-based declarative transaction
Annotation-based declarative transaction
Eight agents in what way spring
1, if they are a pretext proxy object, use the jdk java.long.reflect.proxy agent, the implementation of which generate implementation.
advantage. Because use interface, making the system more loosely coupled
Shortcomings. You need to write an excuse for each target agent
2. If the proxy object is a java class library using subclassing CGLIB target object.
advantage. There is not need to interface
Shortcomings. No use of loosely coupled interface good
Nine, the initialization process IOC container
1.rescourse positioning.
2. Load
3. Registration
X. The principle of AOP: Dynamic proxy, the difference between the reference Article VIII
XI advantage of spring transaction management framework that supports declarative transaction.
to sum up:
Spring Framework advantages:
Convenient decoupling, simplify development:
Spring is a large factory, all objects can create and maintain dependence, to the Spring management (code is not invasive)
1.AOP programming support:
Spring provides Oriented Programming, facilitate the realization of a program intercepting authority, performance monitoring and other functions (for function expansions)
2. declarative transaction support:
Only you need to complete the configuration management of the affairs, without the need for manual programming
3. easy to program test:
Spring for Junit4 supported by Spring annotation convenient test program
Easy integration of a variety of excellent framework:
java-based module
Yes