快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

怎么在SpringBoot中配置Apollo

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

创新互联科技有限公司专业互联网基础服务商,为您提供服务器托管高防服务器,成都IDC机房托管,成都主机托管等互联网服务。

项目引用

 
      com.ctrip.framework.apollo
      apollo-client
      1.4.0
    

引入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问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


本文题目:怎么在SpringBoot中配置Apollo
URL地址:http://6mz.cn/article/jdjooc.html

其他资讯