Spring DI (Dependency Injection)

What Is DI?

当一个类需要依赖另一个对象,把另一个对象实例化之后注入给这个对象的过程我们称之为DI

# Create an object dependency in traditional programming
public class Store {
    private Item item;
 
    public Store() {
        item = new ItemImpl1();    
    }
}

# Using DI
public class Store {
    private Item item;
    
    public Store(Item item) {
        this.item = item;
    }
}

参考:
Intro to Inversion of Control and Dependency Injection with Spring

你可能感兴趣的:(框架,spring,mysql,mybatis)