SpringCloud二:服务提供者

1.创建一个名称为eureka-service的springboot项目后在properties加入相关配置

#服务名称
spring.application.name=eureka-service
#端口号
server.port=8762
#在注册中心中进行注册
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
#启动服务发现的功能,开启了才能调用其它服务
#spring.cloud.config.discovery.enabled=true
#发现的服务的名字--对应注测中心的服务名字
#spring.cloud.config.discovery.serviceId=eurka-server

2.添加provider需要的pom文件

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

3.在SpringBoot的启动类上加上@EnableEurekaClient注解

@SpringBootApplication
@EnableEurekaClient
public class EurekaServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaServiceApplication.class, args);
	}
}

4.启动eureka-service项目后刷新注册中心界面,就会发现eureka-service已经注册到注册中心了

5.写一个接口调用,模拟一下

@RestController
public class demoController {

    @RequestMapping(value = "find",method = RequestMethod.GET)
    public String findInfo(){
        return  "service";
    }
}

6.在浏览器输入http://localhost:8762/find 

这里用到的版本是Spring Boot2.0.3.RELEASE,Spring CloudFinchley.RELEASE。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值