一:建立父工程springclould-parent
父工程的打包方式:pom
父工程鎖定springboot和spring-cloud的版本
父工程的pom檔案如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
二:Service Provider服務提供者
1:建立springcloud-service-provider子子產品
2:繼承父工程
3:修改application.properties配置檔案
1 2 3 4 5 6 7 8 | |
4:主程式加上@EnableEurekaClient注解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
5:啟動該子產品,通路http://localhost:8761/(注冊中心ui界面位址)看到如下界面,代表服務已經注冊成功。

6:暴露一個rest api
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |