码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot 配置Apollo

时间:2019-10-18 10:53:41      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:factor   cto   ipc   prope   ret   autoconf   artifact   not   @Value   

Windows环境安装下载,参考:https://github.com/ctripcorp/apollo

项目引用

 <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.4.0</version>
        </dependency>

引入jar包后,项目配置

1.入口方法加入注解配置   

@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

标签:factor   cto   ipc   prope   ret   autoconf   artifact   not   @Value   

原文地址:https://www.cnblogs.com/notmore/p/11697006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!