在 IntelliJ IDEA 的 Run/Debug Configurations 中,Active profiles
选项通常用于与 Spring Boot 应用程序相关的配置。这是 Spring Boot 特有的一个用来管理不同环境配置的特性,通常用来在开发(dev)、测试(test)、生产(prod)等不同环境中加载不同的应用配置。
Spring Profiles 是 Spring 框架中的一个特性,它允许你在运行时根据不同的配置需求有选择地启用或禁用特定的配置类或配置文件(如 application.properties
或 application.yml
)。
application.properties
:默认的通用配置,将在没有特定 Profile 激活时使用。application-dev.properties
:用于开发环境的配置。application-test.properties
:用于测试环境的配置。application-prod.properties
:用于生产环境的配置。下面是一个 application.properties
的示例:
# application.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=password
开发环境的配置可能如下:
# application-dev.properties
spring.datasource.url=jdbc:mysql://localhost:3306/devdb
spring.datasource.username=devuser
spring.datasource.password=devpassword
logging.level.root=DEBUG
生产环境的配置可能如下:
# application-prod.properties
spring.datasource.url=jdbc:mysql://localhost:3306/proddb
spring.datasource.username=produser
spring.datasource.password=prodpassword
logging.level.root=ERROR
因篇幅问题不能全部显示,请点此查看更多更全内容