diff --git a/springboot-web-req-resp/pom.xml b/springboot-web-req-resp/pom.xml index de8f0bb..339c033 100644 --- a/springboot-web-req-resp/pom.xml +++ b/springboot-web-req-resp/pom.xml @@ -46,7 +46,11 @@ dom4j 2.1.3 - + + org.springframework.boot + spring-boot-starter-actuator + + diff --git a/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java b/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java index 8da9815..07e634c 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java @@ -2,8 +2,11 @@ package com.inmind; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Component; @SpringBootApplication +//@ComponentScan({"com.inmind","dao"})//一旦手动添加了@ComponentScan,那么原始扫描路径就失效了,必须全部手动设置 public class SpringbootWebReqRespApplication { public static void main(String[] args) { 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 57772d6..cc7fbab 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 @@ -6,6 +6,8 @@ import com.inmind.service.EmpService; import com.inmind.service.impl.EmpServiceA; import com.inmind.utils.XmlParserUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoA.java b/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoA.java index 31ccf99..5a322ec 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoA.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/dao/impl/EmpDaoA.java @@ -3,11 +3,12 @@ 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 -- 控制反转 +//@Component //将当前类交给IOC容器管理,成为IOC容器的bean -- 控制反转 +@Repository public class EmpDaoA implements EmpDao { @Override public List listEmp() { diff --git a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceA.java b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceA.java index 9575c5b..c11bb21 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceA.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceA.java @@ -1,11 +1,9 @@ package com.inmind.service.impl; import com.inmind.dao.EmpDao; -import com.inmind.dao.impl.EmpDaoA; 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/EmpServiceB.java b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceB.java index 9ec7733..bddb252 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceB.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/service/impl/EmpServiceB.java @@ -4,11 +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.stereotype.Component; +import org.springframework.stereotype.Service; import java.util.List; -@Component +//@Component +@Service public class EmpServiceB implements EmpService { //获取dao层的对象,获取数据 @Autowired diff --git a/springboot-web-req-resp/src/main/java/com/inmind/utils/XmlParserUtils.java b/springboot-web-req-resp/src/main/java/com/inmind/utils/XmlParserUtils.java index 298988e..2796bc7 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/utils/XmlParserUtils.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/utils/XmlParserUtils.java @@ -3,12 +3,15 @@ package com.inmind.utils; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; +import org.springframework.stereotype.Component; + import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +@Component public class XmlParserUtils { public static List parse(String file , Class targetClass) {