怎么在SpringBoot中配置Apollo
生活随笔
收集整理的這篇文章主要介紹了
怎么在SpringBoot中配置Apollo
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
怎么在SpringBoot中配置Apollo?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
項(xiàng)目引用
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.4.0</version> </dependency>
引入jar包后,項(xiàng)目配置
入口方法加入注解配置
@EnableApolloConfig
packagetop.xzhand;
importcom.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
importorg.mybatis.spring.annotation.MapperScan;
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableApolloConfig
@MapperScan("top.xzhand.mapper")
publicclassJuneApplication{
publicstaticvoidmain(String[]args){
SpringApplication.run(JuneApplication.class,args);
}
}
yml 文件配置項(xiàng)
#阿波羅配置 app: id:juneweb-apollo apollo: #注冊路徑,阿波羅默認(rèn)注冊配置Eureka meta:http://localhost:8080 bootstrap: enabled:true #指定阿波羅中配置項(xiàng)名稱,多個(gè)用逗號隔開 namespaces:application
配置項(xiàng)獲取
packagetop.xzhand.config;
importorg.springframework.beans.factory.annotation.Value;
importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
importtop.xzhand.po.Profix;
@Configuration
@EnableAutoConfiguration
publicclassApolloProperties{
@Value("${juneweb-apollo}")//阿波羅配置中心中配置的key
publicStringprefix;
@Bean
publicProfixprofix(){
Profixp=newProfix();
p.setP(prefix);
System.out.println("prefix=========================**********"+prefix);
returnp;
}
}
總結(jié)
以上是生活随笔為你收集整理的怎么在SpringBoot中配置Apollo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redhat安装tftp的方法
- 下一篇: C++中push与push_back有什