例子4--创建eureka服务提供则2

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、在浏览器中输入

http://localhost:8761

可以看到eurekabussiness项目在eureka注册中心已成功注册

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值