Provider项目
生产者用来提供服务
新建maven项目,引入spring boot的基本jar包
spring-boot-starter-parent:springboot parent模块
spring-boot-starter-web:spring boot web模块(这个包不引入服务将无法注册)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloud.config</groupId>
<artifactId>config</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!--spring boot web模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
引入相关的jar包
eureka的客户端
<!--eureka client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
application配置文件
server:
port: 9998
eureka:
instance:
hostname: 127.0.0.1
lease-expiration-duration-in-seconds: 30
lease-renewal-interval-in-seconds: 10
client:
service-url:
defaultZone: http://${eureka.instance.hostname}:9999/eureka/
spring:
application:
name: eureka-user-manager #注册的用户名
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/uc?useUnicode=true&characterEncoding=utf-8
username: root
password: root
编写启动类
@EnableEurekaClient:eureka的一个客户端
/**
* @author :mmzs
* @date :Created in 2020/1/3 18:05
* @description:用户管理系统启动类
* Provider项目 生产者
* @modified By:
* @version: 1$
*/
@SpringBootApplication
@EnableEurekaClient
public class UserManagerApplication {
public static void main(String[] args) {
SpringApplication.run(UserManagerApplication.class);
}
}
踩过的坑
Cannot execute request on any known server
解决方法