注册中心
引入依赖
<!-- spring colud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<type>pom</type>
</dependency>
<!-- spring eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
启动类加上注解
服务端
@EnableEurekaServer
客户端
@EnableDiscoveryClient
配置文件
server.port=1111
eureka.instance.hostname=localhost
#注册中心不需要注册自己
eureka.client.register-with-eureka=false
#注册中心不需要去发现服务
eureka.client.fetch-registry=false
#设置服务注册中心的URL
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka
客户端
引入依赖
<!-- spring colund -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<type>pom</type>
</dependency>
<!-- spring eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
启动类加上注解
服务端
@EnableEurekaServer
客户端
@EnableEurekaClient
配置文件
#服务端口号
server.port=8080
server.servlet.context-path=/api
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
spring.application.name=service-auth
#数据源配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.44.150:3306/erp?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456