SpringBoot搭建微服务之-搭建服务提供者到eureka

该篇博客是与上篇springboot搭建eureka进行关联的,要实现后面的效果请先完成上篇博客中的效果(https://www.cnblogs.com/chenyuanbo/p/10964590.html),本篇博客继续以图片的形式进行书写,具体如下:

一、建立eureka服务项目

1.File--New-Other-Spring Boot -- SpringStarter Project--Next 

2、设置application.properties文件

  以下需注意以下两点:(1)服务别名主要用于eureka上服务名称的显示;(2)当前服务注册的地址中的地址和端口与上篇博客中的地址和端口要一致,这样才能从上一个项目中的eureka中获取到该项目注册的链接

#设置端口号
server.port=8000
#服务别名 -- 服务注册中心地名称
spring.application.name=app-itmayiedu-member
#当前服务注册到的地址
eureka.client.service-url.defaultZone=http://localhost:8100/eureka
#是否注册自己在注册中心上,默认是不注册(集群的时候需要设置为true)
eureka.client.register-with-eureka=true
#是否需要从eureka上获取自己的注册信息,默认是不需要(集群的时候设置为true)
eureka.client.fetch-registry=true

 

  

 

扫描二维码关注公众号,回复: 6336445 查看本文章

3、创建注册eureka启动类-AppMember 

package com.itemayiedu.api.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

/**  
* @Title: AppMember.java
* @Package:com.itemayiedu.api.controller
* @Description:
* @author:陈远波 
* @date:2019年6月2日
* @version:V1.0  
*/
@SpringBootApplication
@EnableEurekaClient
public class AppMember {
	public static void main(String[] args) {
		SpringApplication.run(AppMember.class,args);
	}
}

 4、创建api类用于测试

package com.itemayiedu.api.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**  
* @Title: MemberApiController.java
* @Package:com.itemayiedu.api.controller
* @Description:
* @author:陈远波 
* @date:2019年6月2日
* @version:V1.0  
*/
@RestController
public class MemberApiController {
	@RequestMapping("/getMember")
	public String getMember() {
		return "我是服务提供者";
	}
}

 

 二、启动项目并进行测试 

1、启动本人springboot中的第一篇博客中建立的服务-springCloud-eureka-2.0;

2、启动springCloud-member-2.0项目

启动成功后如图所示:

 

3、点击服务名:APP-ITMAYIEDU-MEMBER对应的链接:localhost:app-itmayiedu-member:8000

如图所示:

4、更改输入框中的路径,返回控制层中设置的值:http://localhost:8000/getMember

 以上是本人springboot的第二篇博客,后续将继续发布微服务的相关博客,对后期博客感兴趣的朋友可以关注交流,转发请说明出处,本人的博客地址为:https://www.cnblogs.com/chenyuanbo/

 

 

猜你喜欢

转载自www.cnblogs.com/chenyuanbo/p/10965218.html