> For the complete documentation index, see [llms.txt](https://taocares.gitbook.io/development-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://taocares.gitbook.io/development-guide/ji-ben-yuan-li/pei-zhi-guan-li.md).

# 配置管理

Spring Boot支持`.properties`和`.yml`两种格式的配置文件，通常情况下，建议选择对象化的YAML配置文件。

配置文件分为两种，`bootstrap.xml`和`application-{profile}.xml`。前者在应用引导阶段加载，通常用于配置应用的基础信息，如：配置中心地址、应用名、激活的配置等；后者主要配置应用的运行参数，如：MQ地址、数据源、日志等。应用启动时首先加载`bootstrap.xml`，然后加载`spring.profiles.active`对应的`application.xml`。

{% hint style="info" %}
原则上，`boostrap.yml`配置不变的、环境无关的参数，`application.yml`配置动态的、环境相关的参数。
{% endhint %}

示例的配置文件：

{% code title="bootstrap.yml" %}

```yaml
spring:
  application:
    name: demo-application
  profiles:
    active: dev
  boot:
    admin:
      client:
        url: http://localhost:8080
  cloud:
    config:
      discovery:
        enabled: true
        service-id: configserver
      uri: http://localhost:8888
eureka:
  instance:
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka
```

{% endcode %}

{% code title="application-dev.yml" %}

```yaml
server:
  port: 8080
logging:
  level:
    org.springframework: error
    com.netflix: error
spring:
  datasource:
    driver-class-name: oracle.jdbc.OracleDriver
    url: jdbc:oracle:thin:@localhost:1521:demo
    username: demo
    password: demo
    hikari:
      connection-test-query: select * from dual
  jpa:
    generate-ddl: true
    show-sql: true
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 5000
```

{% endcode %}
