一、内容容器 1、SpringBoot支持Tomcat(默认)、Jetty、Undertow等Servlet容器 2、通过添加相关依赖来替换容器 二、profiles 1、什么是 Spring Profiles? Spring Profiles 允许用户根据配置文件(dev,test,prod 等)来注册 bean。因此,当应用程序在开发中运行时,只有某些 bean 可以加载,而在 PRODUCTION中,某些其他 bean 可以加载。假设我们的要求是 Swagger 文档仅适用于 QA 环境,并且禁用所有其他文档。这可以使用配置文件来完成。Spring Boot 使得使用配置文件非常简单。 什么是Profiles? Profile可以让 Spring 对不同的环境提供不同配置的功能,可以通过激活、指定参数等方式快速切换环境 在Spring Boot中多环境配置文件名需要使用application-{profile}.properties的格式,这里的**{profile}**对应的是你的环境标识。例如: application-dev.properties — 这是开发环境 application-prod.properties — 这是生产环境 当前目录的 “/config”的子目录下 当前目录下 classpath根目录的“/config”包下 classpath的根目录下 2、@Component/@Configuration/@ConfigurationProperties可以通过添加@Profile来指定生效环境 3、激活指定profile spring.profiles.active application-{profile}.properties 激活profile的方式 3.1、spring.profiles.active指定 3.2、命令指定 java -jar xxxx.jar --spring.profiles.active=prod 3.3、mvn spring-boot:run -Dspring-boot.run.profiles=dev