diff --git a/springcloud-service-common/pom.xml b/springcloud-service-common/pom.xml index 11c349ed9025972733498db93e763ea1ded16ac3..4eed6cf69a1a14f9e90d9e9d81708c45a211d8bf 100644 --- a/springcloud-service-common/pom.xml +++ b/springcloud-service-common/pom.xml @@ -28,6 +28,12 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + true + diff --git a/springcloud-service-eureka/pom.xml b/springcloud-service-eureka/pom.xml index c00bcd3cbc8542fb9fe6f009df0b24b8ccda8553..86844d7ab5d25d0469773f8c137c9443c4ef04f1 100644 --- a/springcloud-service-eureka/pom.xml +++ b/springcloud-service-eureka/pom.xml @@ -15,10 +15,6 @@ Hoxton.SR12 - - org.springframework.boot - spring-boot-starter-web - org.springframework.cloud spring-cloud-starter-netflix-eureka-server @@ -29,6 +25,15 @@ spring-boot-starter-test test + + + com.kwan.springcloud + springcloud-service-common + 1.0.0 + compile + + + diff --git a/springcloud-service-goods/pom.xml b/springcloud-service-goods/pom.xml index e990e7a7644289d6353db1a0dfe51d3b9a4b9286..b2396b617df7ec4a7481b87e4b81047dab738dbc 100644 --- a/springcloud-service-goods/pom.xml +++ b/springcloud-service-goods/pom.xml @@ -23,11 +23,6 @@ 1.0.0 compile - - org.springframework.boot - spring-boot-starter-web - - org.springframework.boot spring-boot-starter-test @@ -47,16 +42,26 @@ 8.0.11 + + + + + + - com.baomidou - mybatis-plus-extension - 3.5.2 + org.springframework.boot + spring-boot-starter-actuator - + - org.springframework.boot - spring-boot-devtools - true + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + com.google.code.gson + gson + 2.9.0 diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java index c75ad1816bbb4328599bfc8e7af0e12bfc9d3b54..c02e71b0b66b766e9d750f8b063746b7088436e9 100644 --- a/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/GoodsApplication.java @@ -2,7 +2,9 @@ package com.kwan.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +@EnableEurekaClient @SpringBootApplication public class GoodsApplication { diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java new file mode 100644 index 0000000000000000000000000000000000000000..e4c225c16dc483e7b8b4ceb5c9667eb8969ea2de --- /dev/null +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java @@ -0,0 +1,37 @@ +package com.kwan.springcloud.controller; + + +import com.google.gson.Gson; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Slf4j +@RestController +public class HelloController { + + @Autowired + private DiscoveryClient client; + @Autowired + private Registration registration; + + + @RequestMapping("/hello") + public String index() { + + List instances = client.getInstances(registration.getServiceId()); + + log.info(new Gson().toJson(instances)); + + return "hello world"; + } + +} + + diff --git a/springcloud-service-goods/src/main/resources/application.yaml b/springcloud-service-goods/src/main/resources/application.yaml index ccf1d706e0eff0a0e3c8f7b742fa344311f72074..d6347c833cd20e8af785d9e66079fc02d2d21ffd 100644 --- a/springcloud-service-goods/src/main/resources/application.yaml +++ b/springcloud-service-goods/src/main/resources/application.yaml @@ -10,6 +10,21 @@ spring: url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: 716288qwe + application: + name: goods-service #服务名称 + +#服务提供者 +eureka: + client: + service-url: + defaultZone: http://localhost:8766/eureka + +management: + endpoints: + web: + base-path: /actuator #修改访问路径 2.0之前默认是/ 2.0默认是 /actuator 可以通过这个属性值修改 + health: + show-details: always #显示健康具体信息 默认不会显示详细信息 #mybatis-plus配置 mybatis-plus: diff --git a/springcloud-service-portal/pom.xml b/springcloud-service-portal/pom.xml index 5d17b47660d9e547327adf269c5e93b4ebc0d712..a726db8204294125946086d94811d9f32c574ee3 100644 --- a/springcloud-service-portal/pom.xml +++ b/springcloud-service-portal/pom.xml @@ -21,18 +21,19 @@ 1.0.0 compile - - org.springframework.boot - spring-boot-starter-web + spring-boot-starter-test + test + - org.springframework.boot - spring-boot-starter-test - test + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + diff --git a/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java b/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java index e3434bf3b12bd71fba28432581fbede0568c0e99..736622f8b2e6429344bb5ef4d0f51656a8dfec2b 100644 --- a/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java +++ b/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java @@ -2,7 +2,9 @@ package com.kwan.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +@EnableEurekaClient @SpringBootApplication public class PortalApplication { diff --git a/springcloud-service-portal/src/main/resources/application.yaml b/springcloud-service-portal/src/main/resources/application.yaml index 3a43dd9ddbc5a3d5d9a13192a793c167d5b28254..9efa2199c7dfe0d8fe4d081e0028b4e86e6e1cc0 100644 --- a/springcloud-service-portal/src/main/resources/application.yaml +++ b/springcloud-service-portal/src/main/resources/application.yaml @@ -1,3 +1,13 @@ #端口号 server: - port: 8080 \ No newline at end of file + port: 8080 + +spring: + application: + name: portal-service #服务名称 + +#服务提供者 +eureka: + client: + service-url: + defaultZone: http://localhost:8766/eureka \ No newline at end of file