Spring framework learning one (getting started and XML management BEAN)


Although springboot is more commonly used now, only by fully mastering spring can you use springboot handy, so spring again from beginning to end.

1. Framework overview:

1.srping is a lightweight open source JAVAEE framework
2.Sping can solve the complexity of enterprise application development
3.Two cores of Spring: IOC and AOP
1) IOC inversion of control, which means handing over the object creation process to Spring management
2) AOP is aspect-oriented and enhances functions without modifying the source code
4. Spring features:
1) Convenient decoupling, simplified development
2) Aop programming
3) Convenient testing
4) Convenient integration of other frameworks
5) Convenient transaction operations
6) Reduce API development difficulty

Let's demonstrate with Spring5

2. Introductory case:

insert image description here
insert image description here
insert image description here
insert image description here

 <!--测试相关-->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.7.1</version>
            <scope>test</scope>
        </dependency>

        <!--Spring核心基础依赖-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.3.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>5.3.6</version>
        </dependency>
        <!--日志相关-->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

insert image description here
insert image description here
insert image description here
insert image description here
3. IOC introduction
insert image description here

insert image description here

insert image description here
insert image description here

3. DI injection

1. set injection

insert image description here
insert image description here

2. Parameter injection

insert image description here
insert image description here

3. P namespace injection

insert image description here
insert image description here

4. Inject other types

1. Literal volume

①, set a null value

insert image description here

②, special symbol injection

insert image description here
insert image description here

2, external BEAN

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

3. Cascade assignment

insert image description here
insert image description here
insert image description here

4. Inject collection

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

5、FactoryBean

insert image description here
insert image description here

6. The scope of the bean

insert image description here
insert image description here

7. Bean life cycle

The life cycle of the bean is as follows: Execution of construction parameters —> setting properties —> initialization —> obtaining instances —> destroying instances.

insert image description here

insert image description here

8. Automatic assembly

insert image description here
insert image description here
insert image description here
insert image description here

9. External properties file

Take the database configuration file as an example:

①, direct configuration

insert image description here

②. Import external files

screenshot

Guess you like

Origin blog.csdn.net/worilb/article/details/116953392