配置管理
Spring Boot支持.properties和.yml两种格式的配置文件,通常情况下,建议选择对象化的YAML配置文件。
配置文件分为两种,bootstrap.xml和application-{profile}.xml。前者在应用引导阶段加载,通常用于配置应用的基础信息,如:配置中心地址、应用名、激活的配置等;后者主要配置应用的运行参数,如:MQ地址、数据源、日志等。应用启动时首先加载bootstrap.xml,然后加载spring.profiles.active对应的application.xml。
示例的配置文件:
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/eurekaLast updated