유레카 서비스 등록 및 springcloud 노트 발견

1. 유레카 란?

공식 설명 :
Eureka는 Netflix에서 개발 한 서비스 검색 프레임 워크로 REST 기반 서비스이며 주로로드 밸런싱 및 중간 계층 서비스 장애 조치를 달성하기 위해 AWS 도메인에서 실행되는 중간 계층 서비스를 찾는 데 사용됩니다. SpringCloud는이를 하위 프로젝트 spring-cloud-netflix에 통합하여 SpringCloud의 서비스 검색 기능을 실현합니다.

구현 원칙은 다음과 같습니다. 유레카는 레지스트리를 제공하고,이 레지스트리는 서비스를 등록하는 데 사용되며, 서비스 공급자는 레지스트리에 서비스를 제공하고 (서비스 공급자는 유레카 레지스트리 주소를 구성), 소비자는 서비스 공급자가 직접 제공하지 않습니다. 서비스를 받으면 소비자는 먼저 유레카 레지스트리에서 서비스 데이터를 가져온 다음 서비스 공급자를 원격 호출해야합니다.

간단하게

  • 유레카에 공급자 등록 서비스
  • 소비자는 유레카에서 서비스를받습니다.
  • 서비스 제공 업체에 전화

둘째, 단계 사용

여기에 사진 설명 삽입

1. 의존성 소개

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        <version>2.2.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>

2. 구성 파일 작성

server:
  port: 7001

#Eureka配置
eureka:
  instance:
    hostname: eureka7001.com #Eureka服务的实例名称
  client:
    register-with-eureka: false #表示是否向注册中心注册自己
    fetch-registry: false #false表示自己为注册中心
    service-url: #监控页面
      #单机:
      defaultZone: http://${
    
    eureka.instance.hostname}:${
    
    server.port}/eureka/

3. 기본 시작 클래스를 엽니 다.

package com.lhh;

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

@SpringBootApplication
@EnableEurekaServer// Eureka服务端启动
public class EurekaServer_7001 {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(EurekaServer_7001.class, args);
    }
}

그러나 springboot 기본 시작 클래스를 시작하자마자 문제가 발생했으며 오류 내용은 다음과 같습니다.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-05 11:10:24.834 ERROR 21968 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).


Process finished with exit code 1

네티즌의 답변에 따르면 오류의 원인은 주소 값, 데이터베이스 드라이버, 사용자 이름, 비밀번호 등과 같은 데이터 소스의 일부 관련 속성이 응용 프로그램에 구성되지 않았기 때문입니다. , springboot의 기본 시작 클래스에 추가 할 수 있습니다. ** @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})** 데이터 소스의 구성을 무시한다는 의미입니다.

코멘트를 추가 한 후 다시 시작 localhost:7001하면 유레카 서비스 등록 및 센터 페이지에 성공적으로 진입 한 것을 확인할 수 있습니다.
여기에 사진 설명 삽입

요약하자면

사실 저는 학습의 springcloud 단계에 이르렀습니다. 배우기가 더 쉽고 쉬워 질 것입니다. 기본적으로 종속성을 추가하고, 약간의 구성 파일을 작성하고, 시작 클래스에 해당 주석을 추가합니다. 기본적으로 작업은 완료됩니다.

읽은 후 축하합니다, 다시 조금 알고 있습니다!

더 많이 알수록 더 많이 알 수 없습니다!

읽어 주셔서 감사합니다. 여러분의 관심과 의견은 제 연구에 가장 큰 도움이됩니다.

추천

출처blog.csdn.net/qq_41486775/article/details/114385464