1. 新建配置文件
在resource文件夹下创建
- application-dev.properties:
server.port=8090
2. 在主配置文件中选择激活的配置文件
- application.properties:
spring.profiles.active=dev
3. 启动应用程序
此时,注意终端的初始化日志信息
2020-06-28 14:18:19.770 INFO 17828 --- [ main] s.s.SpringbootDemo1Application : The following profiles are active: dev
2020-06-28 14:18:20.525 INFO 17828 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8090 (http)
终端显示被激活的profile是dev,并且端口号被改为8090。