SpringBoot配置Apollo代碼實例
這篇文章主要介紹了SpringBoot配置Apollo代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
Windows環(huán)境安裝下載,參考:https://github.com/ctripcorp/apollo
項目引用
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.4.0</version>
</dependency>
引入jar包后,項目配置
入口方法加入注解配置
@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 文件配置項
# 阿波羅配置 app: id: juneweb-apollo apollo: # 注冊路徑,阿波羅默認注冊配置 Eureka meta: http://localhost:8080 bootstrap: enabled: true # 指定阿波羅中配置項名稱,多個用逗號隔開 namespaces: application
配置項獲取
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;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot+ShardingSphereJDBC實現(xiàn)讀寫分離詳情
這篇文章主要介紹了SpringBoot+ShardingSphereJDBC實現(xiàn)讀寫分離詳情,通過用??MySQL??進行一主一從的主從復(fù)制展開全文內(nèi)容,需要的朋友可以參考一下2022-08-08
Spring應(yīng)用拋出NoUniqueBeanDefinitionException異常的解決方案
這篇文章介紹了解決org.springframework.beans.factory.NoUniqueBeanDefinitionException異常的一些解決方案,從這些解決方案可以看出Spring框架的設(shè)計精妙,遇見此問題的朋友可以參考下該解決方案2021-06-06
springboot整合mybatis plus與druid詳情
這篇文章主要介紹了springboot整合mybatis plus與druid詳情,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的下伙伴可以參考一下2022-09-09

