最近通过Apollo来搭建配置中心,在配置数据库的时候,在Apollo上面更改了数据库的连接信息后程序需要重启才能生效
pom.xml 文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
application.yml 文件
app:
id: first-test
apollo:
meta: http://127.0.0.1:8080/
autoUpdateInjectedSpringProperties: true
bootstrap:
enabled: true
namespaces: database
env: DEV
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: ${name}
password: ${password}
apollo配置
一般改DB连接信息是需要重新启动应用的。如果要试试更新,可以监听配置变动实时更新数据源