springboot整合使用Apollo配置中心

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.启动项目访问:

控制台信息如下:

8.  apollo/admin登录平台.

进行发布

控制台打印:

重新访问,属性已修改