SpringCloud学習ノート-02-EnbaleeurkaServer登録センター

6724 ワード

ホストを登録して、EnbleEurekaServerが起動します。すべてのSpring CloudサービスはEnbaleeurkaServerに登録されます。
テストサイトを実行:
http://localhost:8888/testString
http://localhost:8888/
http://localhost:8765/getOrderByUserList
http://localhost:8769/actuator/info
http://127.0.0.1:8769/api-member/getUserList?token=1224
http://localhost:8764/getOrderByUserList
http://localhost:8762/getUserList
ソースの参考:https://download.csdn.net/download/u011488009/12106481
SpringCloud 学习笔记-02-EnableEurekaServer注册中心_第1张图片
SpringCloud 学习笔记-02-EnableEurekaServer注册中心_第2张图片
 SprigCloud起動のメインクラス:
 package com.ml0115;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class Springcloud1Application {

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

}
もちろんこのserverはRestFulリクエストも設定できます。テストしてもいいです。
package com.ml0115.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public   class  TestControoler{
	 private static final Logger log = LoggerFactory.getLogger(TestControoler.class);
	@RequestMapping("/testString")
	public   String  test() {
		log.info("testString");
		return  "testString";
	}
	@RequestMapping("/testObject")
	public   String  testObject() {
		log.info("testObject");
		return  "testObject";
	}
	
}
もちろん配置のPOM.xmlの配置説明


	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		2.2.2.RELEASE
		 
	
	com.test
	springcloud-1
	0.0.1-SNAPSHOT
	war
	springcloud-1
	      

	
		1.8
		Hoxton.SR1
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.cloud
			spring-cloud-function-web
		
		
			org.springframework.cloud
			spring-cloud-starter
		
		
			org.springframework.cloud
			spring-cloud-starter-task
		

		
			org.springframework.boot
			spring-boot-starter-tomcat
			provided
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
			
				
					org.junit.vintage
					junit-vintage-engine
				
			
		
		
		
			com.alibaba
			fastjson
			1.2.62
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
			org.projectlombok
			lombok
			1.18.10
		
		
			com.google.guava
			guava
			23.0
		
		
			joda-time
			joda-time
			2.9
		
		
			redis.clients
			jedis
			2.8.2
		
		
		
			org.springframework.cloud
			spring-cloud-starter-eureka-server
			1.4.7.RELEASE
		
	

	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				${spring-cloud.version}
				pom
				import
			
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	


最も重要な配置があります。
server:
  port: 8888
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
 
実行結果:
SpringCloud 学习笔记-02-EnableEurekaServer注册中心_第3张图片