提交 9d4457ee 编写于 作者: Q qinyingjie

fix:微服务启动

上级 8bda5ebb
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
......
...@@ -15,10 +15,6 @@ ...@@ -15,10 +15,6 @@
<spring-cloud.version>Hoxton.SR12</spring-cloud.version> <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
...@@ -29,6 +25,15 @@ ...@@ -29,6 +25,15 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.kwan.springcloud</groupId>
<artifactId>springcloud-service-common</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
......
...@@ -23,11 +23,6 @@ ...@@ -23,11 +23,6 @@
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
...@@ -47,16 +42,26 @@ ...@@ -47,16 +42,26 @@
<version>8.0.11</version> <version>8.0.11</version>
</dependency> </dependency>
<!--扩展包 --> <!--扩展包 -->
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>mybatis-plus-extension</artifactId>-->
<!-- <version>3.5.2</version>-->
<!-- </dependency>-->
<!--监控-->
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>mybatis-plus-extension</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
<version>3.5.2</version>
</dependency> </dependency>
<!--热部署-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<optional>true</optional> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency> </dependency>
......
...@@ -2,7 +2,9 @@ package com.kwan.springcloud; ...@@ -2,7 +2,9 @@ package com.kwan.springcloud;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableEurekaClient
@SpringBootApplication @SpringBootApplication
public class GoodsApplication { public class GoodsApplication {
......
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<ServiceInstance> instances = client.getInstances(registration.getServiceId());
log.info(new Gson().toJson(instances));
return "hello world";
}
}
...@@ -10,6 +10,21 @@ spring: ...@@ -10,6 +10,21 @@ spring:
url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/kwan?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: root
password: 716288qwe 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配置
mybatis-plus: mybatis-plus:
......
...@@ -21,18 +21,19 @@ ...@@ -21,18 +21,19 @@
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -2,7 +2,9 @@ package com.kwan.springcloud; ...@@ -2,7 +2,9 @@ package com.kwan.springcloud;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@EnableEurekaClient
@SpringBootApplication @SpringBootApplication
public class PortalApplication { public class PortalApplication {
......
#端口号 #端口号
server: server:
port: 8080 port: 8080
spring:
application:
name: portal-service #服务名称
#服务提供者
eureka:
client:
service-url:
defaultZone: http://localhost:8766/eureka
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册