怎么在SpringBoot中配置Apollo

怎么在SpringBoot中配置Apollo?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。

創(chuàng)新互聯(lián)科技有限公司專業(yè)互聯(lián)網(wǎng)基礎(chǔ)服務(wù)商,為您提供服務(wù)器托管,高防服務(wù)器,成都IDC機(jī)房托管,成都主機(jī)托管等互聯(lián)網(wǎng)服務(wù)。

項(xiàng)目引用

 <dependency>
      <groupId>com.ctrip.framework.apollo</groupId>
      <artifactId>apollo-client</artifactId>
      <version>1.4.0</version>
    </dependency>

引入jar包后,項(xiàng)目配置

入口方法加入注解配置

@EnableApolloConfig

package top.xzhand;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableApolloConfig
@MapperScan("top.xzhand.mapper")
public class JuneApplication {

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

yml 文件配置項(xiàng)

# 阿波羅配置
app:
 id: juneweb-apollo
apollo:
# 注冊(cè)路徑,阿波羅默認(rèn)注冊(cè)配置 Eureka
 meta: http://localhost:8080
 bootstrap:
  enabled: true
#  指定阿波羅中配置項(xiàng)名稱,多個(gè)用逗號(hào)隔開
  namespaces: application

配置項(xiàng)獲取

package top.xzhand.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.xzhand.po.Profix;

@Configuration
@EnableAutoConfiguration
public class ApolloProperties {
  @Value("${juneweb-apollo}") //阿波羅配置中心中配置的key
  public String prefix;
  @Bean
  public Profix profix(){
    Profix p=new Profix();
    p.setP(prefix);
    System.out.println("prefix=========================**********"+prefix);
    return p;
  }
}

關(guān)于怎么在SpringBoot中配置Apollo問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

文章名稱:怎么在SpringBoot中配置Apollo
網(wǎng)站地址:http://bm7419.com/article2/jdjooc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、關(guān)鍵詞優(yōu)化網(wǎng)站建設(shè)、軟件開發(fā)、全網(wǎng)營(yíng)銷推廣、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)