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

Apollo整合SpringBoot开发

时间:2020-01-19 20:46:33      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:rap   pom   return   ruid   OLE   rest   ace   log   ESS   

创建项目

pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

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

    </dependencies>

 必选配置

app.id=account-service
apollo.cacheDir=/opt/data/apollo‐config
apollo.cluster=SHAJQ

 

apollo:
  meta: http://192.168.180.137:8080
  bootstrap:
    enabled: true
    eagerLoad:
      enabled: true
    namespaces: application,micro_service.spring‐boot‐http,spring‐rocketmq,spring-boot-druid

 

配置类

@SpringBootApplication
@EnableApolloConfig
public class AccountServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(AccountServiceApplication.class, args);
    }

}

 

web层

@RestController
public class AccountController {

    @Value("${sms.enable}")
    private Boolean smsEnable;

    @GetMapping("/hi")
    public String hi() {
        return "hi";
    }

    @Value("${timeout}")
    private Long timeout;

    @GetMapping("/timeout")
    public Long getTimeout() {
        return timeout;
    }

}

技术图片

 

 进行读取配置

技术图片

 

 说明配置已经生效了。

 

Apollo整合SpringBoot开发

标签:rap   pom   return   ruid   OLE   rest   ace   log   ESS   

原文地址:https://www.cnblogs.com/dalianpai/p/12215513.html

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