怎么在SpringBoot中配置阿波罗

  介绍

怎么在SpringBoot中配置阿波罗?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

<强>项目引用

, & lt; dependency>   ,,,,,& lt; groupId> com.ctrip.framework.apollo   ,,,,,& lt; artifactId> apollo-client   ,,,,,& lt; version> 1.4.0   ,,,& lt;/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文件配置项

#,阿波罗配置   应用:   ,id: juneweb-apollo   阿波罗:   #,注册路径,阿波罗默认注册配置,尤里卡   ,元:http://localhost: 8080   ,引导:   启用才能:真实   #,,指定阿波罗中配置项名称,多个用逗号隔开   名称空间:,才能应用

<强>配置项获取

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}“),//阿波罗配置中心中配置的关键   public 才能String 前缀;   ,@ bean   public 才能;Profix  profix () {   ,,,Profix  p=new  Profix ();   ,,,p.setP(前缀);   ,,,System.out.println(“前缀=========================* * * * * * * * * *“+前缀);   ,,,return  p;   ,,}   }

关于怎么在SpringBoot中配置阿波罗问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

怎么在SpringBoot中配置阿波罗