javaEEday05-分层解耦-IOC&DI-DI详解
This commit is contained in:
@@ -5,7 +5,9 @@ import com.inmind.pojo.Result;
|
||||
import com.inmind.service.EmpService;
|
||||
import com.inmind.service.impl.EmpServiceA;
|
||||
import com.inmind.utils.XmlParserUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -18,6 +20,8 @@ public class EmpController {
|
||||
|
||||
//定义业务层对象
|
||||
@Autowired //运行时,IOC容器会提供该类型的bean对象,并赋值给该变量---依赖注入
|
||||
@Qualifier("empServiceB") //方式二:解决同一类型,有多个bean对象
|
||||
//@Resource(name = "empServiceA") 方式三:解决同一类型,有多个bean对象
|
||||
private EmpService empService;//多态
|
||||
|
||||
//定义一个获取员工列表的接口
|
||||
|
||||
@@ -4,9 +4,12 @@ import com.inmind.dao.EmpDao;
|
||||
import com.inmind.pojo.Emp;
|
||||
import com.inmind.service.EmpService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Primary 方式一:解决同一类型,有多个bean对象
|
||||
@Service
|
||||
public class EmpServiceA implements EmpService {
|
||||
//获取dao层的对象,获取数据
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user