您的当前位置:首页正文

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

来源:九壹网

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

一、建立eureka服务项目

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

2、设置application.properties文件

#设置端口号
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

 

  

 

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、更改输入框中的路径,返回控制层中设置的值:

 

 

 

转载于:https://www.cnblogs.com/chenyuanbo/p/10965218.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Top