日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

springboot 替换tomcat_Springboot (二十八)云配置服务器

發(fā)布時間:2025/4/16 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot 替换tomcat_Springboot (二十八)云配置服务器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Spring Cloud Configuration Server是一個集中式應(yīng)用程序,可管理所有與應(yīng)用程序相關(guān)的配置屬性。 在本章中,將詳細了解如何創(chuàng)建Spring Cloud Configuration服務(wù)器。

創(chuàng)建Spring Cloud配置服務(wù)器

首先,從Spring Initializer頁面下載Spring Boot項目,然后選擇Spring Cloud Config Server依賴項。 觀察下面給出的截圖 -

現(xiàn)在,在構(gòu)建配置文件中添加Spring Cloud Config服務(wù)器依賴項,如下所述 -

Maven用戶可以將以下依賴項添加到pom.xml 文件中。

org.springframework.cloud spring-cloud-config-server

Gradle用戶可以在 build.gradle 文件中添加以下依賴項。

compile('org.springframework.cloud:spring-cloud-config-server')

現(xiàn)在,在主Spring Boot應(yīng)用程序類文件中添加@EnableConfigServer批注。 @EnableConfigServer注解使Spring Boot應(yīng)用程序充當(dāng)配置服務(wù)器。

Spring Boot應(yīng)用程序類文件如下 -

package com.felix.configserver;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication@EnableConfigServerpublic class ConfigserverApplication { public static void main(String[] args) { SpringApplication.run(ConfigserverApplication.class, args); }}

現(xiàn)在,將以下配置添加到屬性文件中,并將application.properties 文件替換為bootstrap.properties 文件。使用下面給出的代碼 -

server.port = 8888spring.cloud.config.server.native.searchLocations=file:///C:/configprop/spring.profiles.active=native

Configuration Server在Tomcat端口8888 上運行,應(yīng)用程序配置屬性從本機搜索位置加載。

現(xiàn)在,在file///C:/configprop/中,放置客戶端應(yīng)用程序 - application.properties文件。 例如,您的客戶端應(yīng)用程序名稱是config-client,然后將application.properties文件重命名為config-client.properties,并將屬性文件放在路徑file///C:/configprop/上。

config-client屬性文件的代碼如下 -

welcome.message = Welcome to Spring cloud config server

完整的構(gòu)建配置文件如下 -

Maven用戶可以使用下面給出的 pom.xml -

<?xml version = "1.0" encoding = "UTF-8"?>4.0.0com.felix configserver 0.0.1-SNAPSHOTjarconfigserverDemo project for Spring Bootorg.springframework.boot spring-boot-starter-parent 1.5.9.RELEASEUTF-8UTF-81.8Edgware.RELEASEorg.springframework.cloud spring-cloud-config-server org.springframework.boot spring-boot-starter-test testorg.springframework.cloud spring-cloud-dependencies ${spring-cloud.version}pomimportorg.springframework.boot spring-boot-maven-plugin

Gradle用戶可以使用下面給出的build.gradle 文件 -

buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }}apply plugin: 'java'apply plugin: 'eclipse'apply plugin: 'org.springframework.boot'group = 'com.felix'version = '0.0.1-SNAPSHOT'sourceCompatibility = 1.8repositories { mavenCentral()}ext { springCloudVersion = 'Edgware.RELEASE'}dependencies { compile('org.springframework.cloud:spring-cloud-config-server') testCompile('org.springframework.boot:spring-boot-starter-test')}dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" }}

現(xiàn)在,創(chuàng)建一個可執(zhí)行的JAR文件,并使用以下Maven或Gradle命令運行Spring Boot應(yīng)用程序 -

對于Maven,請使用下面給出的命令 -

mvn clean install

在“BUILD SUCCESS”之后,可以在target目錄下找到JAR文件。

對于Gradle,請使用下面給出的命令 -

gradle clean build

在“BUILD SUCCESSFUL”之后,可在build/libs目錄下找到JAR文件。

使用以下命令運行JAR文件 -

java –jar

現(xiàn)在,應(yīng)用程序已在Tomcat端口8888上啟動。

現(xiàn)在,在Web瀏覽器上訪問URL => http://localhost:8888/config-client /default/master,可以看到config-client應(yīng)用程序配置屬性,如下所示。

總結(jié)

以上是生活随笔為你收集整理的springboot 替换tomcat_Springboot (二十八)云配置服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。