From 374ee007f16b18e7b48ac0132f06da52bfdef3a9 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 19 Sep 2026 15:46:22 +0800 Subject: [PATCH] =?UTF-8?q?javaEEday05-=E5=88=86=E5=B1=82=E8=A7=A3?= =?UTF-8?q?=E8=80=A6-IOC&DI-IOC=E8=AF=A6=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- springboot-web-req-resp/pom.xml | 4 ++++ .../src/main/java/com/inmind/controller/EmpController.java | 2 +- .../src/main/java/com/inmind/dao/impl/EmpDaoImplA.java | 4 ++-- .../main/java/com/inmind/service/impl/EmpServiceImplA.java | 2 -- .../main/java/com/inmind/service/impl/EmpServiceImplB.java | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/springboot-web-req-resp/pom.xml b/springboot-web-req-resp/pom.xml index f2ae0ad..450bab3 100644 --- a/springboot-web-req-resp/pom.xml +++ b/springboot-web-req-resp/pom.xml @@ -47,6 +47,10 @@ dom4j 2.1.3 + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/springboot-web-req-resp/src/main/java/com/inmind/controller/EmpController.java b/springboot-web-req-resp/src/main/java/com/inmind/controller/EmpController.java index 6cee1a7..7e73178 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/controller/EmpController.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/controller/EmpController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; -@RestController +@RestController//底层带有@Controller,本身是交给IOC容器管理 public class EmpController { //设置一个员工业务对象 @Autowired//运行时,IOC容器会提供该类型的bean对象,并赋值给该变量----依赖注入 diff --git a/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoImplA.java b/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoImplA.java index f9d9f8e..6b54e7c 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoImplA.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoImplA.java @@ -3,11 +3,11 @@ package com.inmind.dao.impl; import com.inmind.dao.EmpDao; import com.inmind.pojo.Emp; import com.inmind.utils.XmlParserUtils; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; import java.util.List; -@Component //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转 +@Repository//将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转 public class EmpDaoImplA implements EmpDao { @Override public List listEmp() { diff --git a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplA.java b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplA.java index 053983a..2e14be2 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplA.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplA.java @@ -1,11 +1,9 @@ package com.inmind.service.impl; import com.inmind.dao.EmpDao; -import com.inmind.dao.impl.EmpDaoImplA; import com.inmind.pojo.Emp; import com.inmind.service.EmpService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import java.util.List; diff --git a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplB.java b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplB.java index 38e7bbc..3aeb153 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplB.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceImplB.java @@ -4,11 +4,11 @@ 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.stereotype.Component; +import org.springframework.stereotype.Service; import java.util.List; -@Component //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转 +@Service //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转 public class EmpServiceImplB implements EmpService { //设置一个dao的成员变量 @Autowired//运行时,IOC容器会提供该类型的bean对象,并赋值给该变量----依赖注入