欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud2020版本配置與環(huán)境搭建教程詳解

 更新時(shí)間:2020年12月28日 15:06:00   作者:ZM つ小灰灰的成長(zhǎng)  
這篇文章主要介紹了SpringCloud2020版本配置與環(huán)境搭建教程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1、maven父子工程搭建

項(xiàng)目使用maven工程搭建,下面是工程的結(jié)構(gòu)圖。SpringCloud2020是父工程,僅負(fù)責(zé)依賴的管理,eureka是注冊(cè)中心的服務(wù)端,testclient是測(cè)試的客戶端。

在這里插入圖片描述

1.1 父工程pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>org.example</groupId>
 <artifactId>SpringCloud2020</artifactId>
 <packaging>pom</packaging>
 <version>1.0-SNAPSHOT</version>
 <modules>
  <module>eureka</module>
  <module>testclient</module>
 </modules>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.4.1</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>

 <dependencyManagement>
  <dependencies>
   <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <!-- Provide the latest stable Spring Cloud release train version (e.g. 2020.0.0) -->
    <version>2020.0.0</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>
  </dependencies>
 </dependencyManagement>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>

1.2 eureka子工程pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <parent>
  <artifactId>SpringCloud2020</artifactId>
  <groupId>org.example</groupId>
  <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>

 <artifactId>eureka</artifactId>

 <dependencies>
  <dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  </dependency>
 </dependencies>
</project>

1.3 testclient子工程pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <parent>
  <artifactId>SpringCloud2020</artifactId>
  <groupId>org.example</groupId>
  <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>

 <artifactId>testclient</artifactId>
 <dependencies>
 	<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  </dependency>
  <!--引入WebStart-->
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 </dependencies>
</project>

2、配置application

2.1 eureka 配置

server:
 port: 20001 #eureka運(yùn)行的端口號(hào)
 address: 127.0.0.1 #注冊(cè)中心運(yùn)行地址
 servlet:
 context-path: /server #eureka注冊(cè)中心管理界面地址
eureka:
 client:
 register-with-eureka: false #是否加入eureka注冊(cè)表
 fetch-registry: false #還是向eureka請(qǐng)求注冊(cè)信息表
 service-url:
  defaultZone: http://${server.address}:${server.port}/eureka #注冊(cè)中心地址,其它服務(wù)需要注冊(cè)到該地址

2.1 testclient 配置

server:
 port: 20002
# Spring
spring:
 application:
 name: test_service
# Eureka
eureka:
 client:
 service-url:
  defaultZone: http://127.0.0.1:20001/eureka #這里的port與eureka的端口對(duì)應(yīng)
 instance:
 lease-renewal-interval-in-seconds: 5 # 每隔5秒發(fā)送一次心跳
 lease-expiration-duration-in-seconds: 10 # 10秒不發(fā)送就過期
 prefer-ip-address: true
 instance-id: ${spring.application.name}:${server.port}

3、啟動(dòng)類

3.1 Eureka啟動(dòng)類EurekaApplication

package org.example.demo;

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

@SpringBootApplication
@EnableEurekaServer
public class DemoApplication {

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

}

3.2 TestClient啟動(dòng)類TestClientApplication

package org.example.demo;

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

@SpringBootApplication
@EnableEurekaClient
public class TestClientApplication {

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

}

4、運(yùn)行結(jié)果

如果沒有意外,那么你將看到

在這里插入圖片描述

如果啟動(dòng)testclient時(shí)報(bào)錯(cuò)

在這里插入圖片描述

請(qǐng)檢查testclient工程的依賴中是否存在下面的依賴項(xiàng),如果沒有,請(qǐng)?zhí)砑印T蚩赡苁莈ureka-client依賴spring-boot-starter-web

 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

如果沒有出現(xiàn)TEST_SERVICE,并且testclient出現(xiàn)以下報(bào)錯(cuò)

在這里插入圖片描述

請(qǐng)檢查testclient配置的defaultZone是否與eureka配置對(duì)應(yīng),并清空已經(jīng)構(gòu)建的內(nèi)容,再重新啟動(dòng)eureka,testclient。
在testclient控制臺(tái)看到以下日志信息,說明注冊(cè)成功。

在這里插入圖片描述

訪問管理界面默認(rèn)使用127.0.0.1:port,如果要改變它,請(qǐng)按照下面的提示配置

server:
 port: 20001 #eureka運(yùn)行的端口號(hào)
 address: 127.0.0.1 #管理界面的地址
 servlet:
 context-path: /eureka-ui#管理界面的context-path
eureka:
 client:
 register-with-eureka: false #是否加入eureka注冊(cè)表
 fetch-registry: false #是否向eureka請(qǐng)求注冊(cè)信息表
 service-url:
  defaultZone: http://127.0.0.1:${server.port}/eureka # 配置注冊(cè)中心的地址,其它服務(wù)注冊(cè)的時(shí)候使用。

到此這篇關(guān)于SpringCloud2020版本配置與環(huán)境搭建教程詳解的文章就介紹到這了,更多相關(guān)SpringCloud2020版本配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 輕松掌握java裝飾者模式

    輕松掌握java裝飾者模式

    這篇文章主要幫助大家輕松掌握java裝飾者模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Java正則表達(dá)式驗(yàn)證固定電話號(hào)碼符合性

    Java正則表達(dá)式驗(yàn)證固定電話號(hào)碼符合性

    這篇文章主要介紹了Java正則表達(dá)式驗(yàn)證固定電話號(hào)碼符合性的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-09-09
  • 淺談Java中常用數(shù)據(jù)結(jié)構(gòu)的實(shí)現(xiàn)類 Collection和Map

    淺談Java中常用數(shù)據(jù)結(jié)構(gòu)的實(shí)現(xiàn)類 Collection和Map

    下面小編就為大家?guī)硪黄獪\談Java中常用數(shù)據(jù)結(jié)構(gòu)的實(shí)現(xiàn)類 Collection和Map。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-09-09
  • Java TCP網(wǎng)絡(luò)通信協(xié)議詳細(xì)講解

    Java TCP網(wǎng)絡(luò)通信協(xié)議詳細(xì)講解

    TCP/IP是一種面向連接的、可靠的、基于字節(jié)流的傳輸層通信協(xié)議,它會(huì)保證數(shù)據(jù)不丟包、不亂序。TCP全名是Transmission?Control?Protocol,它是位于網(wǎng)絡(luò)OSI模型中的第四層
    2022-09-09
  • 簡(jiǎn)述Java編程語言中的逃逸分析

    簡(jiǎn)述Java編程語言中的逃逸分析

    這篇文章主要介紹了簡(jiǎn)述Java編程語言中的逃逸分析,包括其定義、作用、類型及理論基礎(chǔ)等相關(guān)內(nèi)容,十分具有參考價(jià)值,需要的朋友可以了解下。
    2017-09-09
  • springcloud?gateway無法路由問題的解決

    springcloud?gateway無法路由問題的解決

    gateway網(wǎng)關(guān)的重要作用之一便是進(jìn)行路由轉(zhuǎn)發(fā)工作,下面這篇文章主要給大家介紹了關(guān)于springcloud?gateway無法路由問題的解決方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-05-05
  • java實(shí)現(xiàn)RedisTemplate操作哈希數(shù)據(jù)

    java實(shí)現(xiàn)RedisTemplate操作哈希數(shù)據(jù)

    RedisTemplate是Spring Data Redis提供的一個(gè)用于操作Redis的模板類,本文主要介紹了java實(shí)現(xiàn)RedisTemplate操作哈希數(shù)據(jù),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-09-09
  • Java中的什么場(chǎng)景使用遞歸,如何使用遞歸

    Java中的什么場(chǎng)景使用遞歸,如何使用遞歸

    這篇文章主要介紹了Java中的什么場(chǎng)景使用遞歸,如何使用遞歸的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • JAVA正則表達(dá)式提取key-value類型字符值代碼實(shí)例

    JAVA正則表達(dá)式提取key-value類型字符值代碼實(shí)例

    這篇文章主要給大家介紹了關(guān)于JAVA正則表達(dá)式提取key-value類型字符值的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-10-10
  • Java?Maven構(gòu)建工具中mvnd和Gradle誰更快

    Java?Maven構(gòu)建工具中mvnd和Gradle誰更快

    這篇文章主要介紹了Java?Maven構(gòu)建工具中mvnd和Gradle誰更快,mvnd?是?Maven?Daemon?的縮寫?,翻譯成中文就是?Maven?守護(hù)進(jìn)程,下文更多相關(guān)資料,需要的小伙伴可以參考一下
    2022-05-05

最新評(píng)論