最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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)文章

  • idea編輯XML文件出現(xiàn):Tag name expected報(bào)錯(cuò)的解決

    idea編輯XML文件出現(xiàn):Tag name expected報(bào)錯(cuò)的解決

    在XML中,一些特殊字符不能直接使用,因?yàn)樗鼈儽槐A粲糜赬ML文檔的結(jié)構(gòu)和語(yǔ)法,如果直接使用這些保留字符,會(huì)導(dǎo)致解析錯(cuò)誤,正確的做法是使用實(shí)體引用或字符引用,或者使用CDATA標(biāo)記將這些字符包裹起來
    2025-01-01
  • spring的同一定時(shí)任務(wù)上一次的任務(wù)未結(jié)束前不會(huì)啟動(dòng)這次任務(wù)問題

    spring的同一定時(shí)任務(wù)上一次的任務(wù)未結(jié)束前不會(huì)啟動(dòng)這次任務(wù)問題

    這篇文章主要介紹了spring的同一定時(shí)任務(wù)上一次的任務(wù)未結(jié)束前不會(huì)啟動(dòng)這次任務(wù)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • java對(duì)象序列化與反序列化原理解析

    java對(duì)象序列化與反序列化原理解析

    這篇文章主要介紹了java對(duì)象序列化與反序列化原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • SpringBoot+MyBatis實(shí)現(xiàn)登錄案例

    SpringBoot+MyBatis實(shí)現(xiàn)登錄案例

    前端時(shí)間在網(wǎng)上看到有朋友在學(xué)習(xí)springboot項(xiàng)目的搭建過程,今天就抽空給大家分享一個(gè)案例幫助大家學(xué)習(xí)SpringBoot+MyBatis實(shí)現(xiàn)登錄功能,具體實(shí)現(xiàn)代碼跟隨小編一起看看吧
    2021-06-06
  • mybatis分割字符串并循環(huán),實(shí)現(xiàn)in多個(gè)參數(shù)的操作

    mybatis分割字符串并循環(huán),實(shí)現(xiàn)in多個(gè)參數(shù)的操作

    這篇文章主要介紹了mybatis分割字符串并循環(huán),實(shí)現(xiàn)in多個(gè)參數(shù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • Java中Synchronized鎖的使用和原理詳解

    Java中Synchronized鎖的使用和原理詳解

    這篇文章主要介紹了Java中Synchronized鎖的使用和原理詳解,synchronized是?Java?內(nèi)置的關(guān)鍵字,它提供了一種獨(dú)占的加鎖方式,synchronized的獲取和釋放鎖由JVM實(shí)現(xiàn),用戶不需要顯示的釋放鎖,非常方便,需要的朋友可以參考下
    2023-07-07
  • Springboot使用@WebListener?作為web監(jiān)聽器的過程解析

    Springboot使用@WebListener?作為web監(jiān)聽器的過程解析

    這篇文章主要介紹了Springboot使用@WebListener作為web監(jiān)聽器的過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • Resty極簡(jiǎn)restful框架快速接入Spring

    Resty極簡(jiǎn)restful框架快速接入Spring

    這篇文章主要為大家介紹了Resty極簡(jiǎn)的restful框架快速接入Spring詳細(xì)說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-03-03
  • maven多moudle項(xiàng)目在idea里面顯示多個(gè)root問題及解決

    maven多moudle項(xiàng)目在idea里面顯示多個(gè)root問題及解決

    這篇文章主要介紹了maven多moudle項(xiàng)目在idea里面顯示多個(gè)root問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • IDEA中try catch拋異??旖萱I分享

    IDEA中try catch拋異??旖萱I分享

    在編寫Java代碼時(shí),使用IDEA的快捷鍵CTRL+ALT+t可以快速生成try..catch語(yǔ)句塊,有效提高編碼效率,首先選擇需要處理的代碼片段,然后按下快捷鍵,選擇try/catch選項(xiàng),即可自動(dòng)包圍選中代碼,這一快捷操作簡(jiǎn)化了異常處理步驟,減少了手動(dòng)編寫的時(shí)間,是編程中的實(shí)用技巧
    2024-10-10

最新評(píng)論

余姚市| 长泰县| 金秀| 清远市| 左贡县| 菏泽市| 常山县| 洪江市| 靖西县| 建始县| 舟山市| 奈曼旗| 平武县| 南汇区| 凤冈县| 黑河市| 原阳县| 阳城县| 镇雄县| 广平县| 霍城县| 东宁县| 平度市| 灌南县| 永州市| 吴忠市| 连城县| 井冈山市| 桃源县| 波密县| 柯坪县| 文登市| 香格里拉县| 洪泽县| 商都县| 高安市| 工布江达县| 佛山市| 张家口市| 台江县| 通州区|