怎么在SpringBoot中配置Apollo

发布时间:2021-03-05 17:16:54 作者:Leah
来源:亿速云 阅读:409

怎么在SpringBoot中配置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;
  }
}

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

推荐阅读:
  1. 学习Apollo服务配置中心,与SpringBoot整合
  2. 详解Springboot中apollo

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot apollo

上一篇:如何在Spring Boot中对Swagger进行配置

下一篇:如何在springboot中对redis进行配置

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》