1、在空项目中添加模块
2、下一步
3、创建项目eurekabussinessinfo
4、注意,下面选择的是Eureka Discovery Client
5、而后点击下一步,最后完成
6、在eurekabussinessinfo项目中添加注解
@EnableDiscoveryClient
7、修改application.yml如下
server:
port: 8763 #端口
spring:
application:
name: eurekabussinessinfo
eureka:
instance:
prefer-ip-address: true #一定要使能为true,否则可能cry
client:
service-url.defaultZone: http://localhost:8761/eureka/
8、添加controller包
9、在controller下添加类
BussinessInfoController
10、简单添加个restful的响应
package com.xachen.demo.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BussinessInfoController {
@Value("${server.port}")
String port;
@RequestMapping("/bussinessinfo")
public String test(){
return "bussinessinfo server 被调用了!:" +port;
}
}
11、在项目eurekaregcenter启动和eurekadeviceinfo启动的基础上
12、启动eurekabussiness项目,输入
http://localhost:8763/bussinessinfo
13、在浏览器中输入
可以看到eurekabussiness项目在eureka注册中心已成功注册