springboot整合使用Apollo配置中心

1.创建C:\opt\settings\server.properties目录,并填写内容【env=DEV】

2.创建springboot 项目 版本1.5.17.RELEASE

3.添加Apollo依赖

<!--apollo相关jar包-->
<dependency>
	<groupId>com.ctrip.framework.apollo</groupId>
	<artifactId>apollo-client</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
	<groupId>com.ctrip.framework.apollo</groupId>
	<artifactId>apollo-core</artifactId>
	<version>1.1.0</version>
</dependency>

 4.编写application.yml文件

server:
  port: 9000
spring:
  application:
    name: apolloDeno
app:
  id: demoApollo
# set apollo meta server address, adjust to actual address if necessary
apollo:
  meta: http://192.168.159.146:8080

5.springboot启动类添加注解@EnableApolloConfig

@SpringBootApplication
@EnableApolloConfig
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication .class, args);
	}
}
6.编写controller
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {


    @Value("${hello:apollo}")
    private String hello;

    @RequestMapping("/helloApollo")
    @ResponseBody
    public String sayApollo(){
        return "hello "+hello;
    }

}

 

7.启动项目访问:http://localhost:9000/helloApollo

控制台信息如下:

8. http://192.168.159.146:8070 apollo/admin登录平台.

进行发布

控制台打印:

重新访问,属性已修改

  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值