1、在服务提供者application.properties文件中添加配置
#服务的端口号
server.port=8081
#微服务的名称
spring.application.name=cloud-payment-service
#指定数据源连接池的类型
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#数据库连接池的驱动
spring.datasource.driver-class-name=org.gjt.mm.mysql.Driver
#数据库连接池的url
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
#数据路的用户名
spring.datasource.username=duchao
#数据库的密码
spring.datasource.password=123456
#指定mapper文件的位置
mybatis.mapper-locations=classpath:mapper/*.xml
#指定实体类包的别名
mybatis.type-aliases-package=com.springcloud.enties
#表示是否将自己注册进EurekaServer,默认为true。
eureka.client.register-with-eureka=true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡。
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:7001/eureka
2、在服务提供者pom文件中添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
3、在启动类中添加注解
package com.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* @author dc
* @date 2020/7/18 - 15:34
*/
/**
* 主启动类
*/
@SpringBootApplication
@EnableEurekaClient //表示开启eureka客户端
public class PaymentMain {
public static void main(String[] args) {
SpringApplication.run(PaymentMain.class, args);
}
}
截图