Spring jar包:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
A: Spring Tags:
beans root tag
Each corresponds to a bean bean javabean
id: identifier uniquely identifies
class: javabean instantiation of fully qualified class name for an object created by the reflection of
scope: use of objects!
scope of singleton: Default single embodiment is the same every time getBean
scope of the prototype: a prototype meaning but here are more cases! ! Every time an object is created out getBean
II: Test of three ways getBean:
getBean("id")
getBean("id",T.class)
getBean(T.class)
Three: Spring dependency injection (DI) in two ways
1.set injection method is strongly recommended
Set by the injection method
must require implantation method attributes are set
Step
1: You have to inject the property must have set method
2: Add a <property> injected in the bean
<property>: Properties tab
rear set method name class name
if it is a simple value type to a value (to directly assigns them)
if the disassociation pojo type ref the bean id
2. The structure injection method to know about understanding what some places to use later
Completed by the constructor injection
1: There must be constructed with participation of
2: constructor-arg: all the properties must write a class is full-time configuration parameters arranged meaning
Example: <the bean ID = "Account" class = "com.itheima.pojo.Account">
<name = constructor-Arg " name "value =" Jack "/>
<constructor Arg-name =" ID "value =" 123 "/>
<constructor Arg-name =" Money "value =" 10000.1 "/>
</ the bean>
Four: IOC concept
IOC inverse of control inversion of control!
When an object is required, and not to the new, to find spring, taken out on it.
We just lost a right (the right to create objects), was a well-being (the object directly from the spring to get in).
Thought known as IOC, inversion of control!
effect:
IOC for decoupling between components! !
IV: Description IOC face questions and DI
IOC and DI is one thing, angle just described is not the same! !
IOC inversion of control, you lose the right to a created object to obtain a benefit (subject to find spring).
Spring is in the reflection to create objects to complete! !
DI in the process of creating an object, the property is set to object! !
DI dependent IOC happen! !
Five: complex type injection:
Example: <Property name = "myStrs">
<Array>
<value> Zhai day Pro </ value>
<value> Xiubo </ value>
<value> Haibo </ value>
</ Array>
</ Property>
VI: face questions: ApplicationContext and BeanFactory
Are starting container interface, loaded object is not the same point in time
ApplicationContext belong immediately after loading refers to the completion of reading the configuration file, put all the objects are created out! !
Delay in BeanFactory load refers to create getBean time to go! !