javascript
springboot 替换tomcat_Springboot (二十八)云配置服务器
Spring Cloud Configuration Server是一個集中式應用程序,可管理所有與應用程序相關的配置屬性。 在本章中,將詳細了解如何創建Spring Cloud Configuration服務器。
創建Spring Cloud配置服務器
首先,從Spring Initializer頁面下載Spring Boot項目,然后選擇Spring Cloud Config Server依賴項。 觀察下面給出的截圖 -
現在,在構建配置文件中添加Spring Cloud Config服務器依賴項,如下所述 -
Maven用戶可以將以下依賴項添加到pom.xml 文件中。
org.springframework.cloud spring-cloud-config-serverGradle用戶可以在 build.gradle 文件中添加以下依賴項。
compile('org.springframework.cloud:spring-cloud-config-server')現在,在主Spring Boot應用程序類文件中添加@EnableConfigServer批注。 @EnableConfigServer注解使Spring Boot應用程序充當配置服務器。
Spring Boot應用程序類文件如下 -
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); }}現在,將以下配置添加到屬性文件中,并將application.properties 文件替換為bootstrap.properties 文件。使用下面給出的代碼 -
server.port = 8888spring.cloud.config.server.native.searchLocations=file:///C:/configprop/spring.profiles.active=nativeConfiguration Server在Tomcat端口8888 上運行,應用程序配置屬性從本機搜索位置加載。
現在,在file///C:/configprop/中,放置客戶端應用程序 - application.properties文件。 例如,您的客戶端應用程序名稱是config-client,然后將application.properties文件重命名為config-client.properties,并將屬性文件放在路徑file///C:/configprop/上。
config-client屬性文件的代碼如下 -
welcome.message = Welcome to Spring cloud config server完整的構建配置文件如下 -
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-pluginGradle用戶可以使用下面給出的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}" }}現在,創建一個可執行的JAR文件,并使用以下Maven或Gradle命令運行Spring Boot應用程序 -
對于Maven,請使用下面給出的命令 -
mvn clean install在“BUILD SUCCESS”之后,可以在target目錄下找到JAR文件。
對于Gradle,請使用下面給出的命令 -
gradle clean build在“BUILD SUCCESSFUL”之后,可在build/libs目錄下找到JAR文件。
使用以下命令運行JAR文件 -
java –jar現在,應用程序已在Tomcat端口8888上啟動。
現在,在Web瀏覽器上訪問URL => http://localhost:8888/config-client /default/master,可以看到config-client應用程序配置屬性,如下所示。
總結
以上是生活随笔為你收集整理的springboot 替换tomcat_Springboot (二十八)云配置服务器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 各个版本通道_绝地求生各个参数对画面的影
- 下一篇: java代码如何降低重复率_影响网站跳出