springboot 五-配置

常用配置:更改服务端口号 , 默认的端口号是8080

yaml

yaml配置
//注意springboot版本不一样的时候,格式会有些出入, 本次的SpringBoot ::  (v2.5.8)
server:
  port:7777
servlet:
  session:
    timeout: 30m  #测试的话 需要长一些
config:
  key:YYYYY

多环境配置

1. 在配置文件中指定启动某个环境

创建一个application.yaml 并指定active的值 就会启动该值对应的配置文件
运行的时候 会自动读取该文件 中active对应的值 比如test 那会将application.yaml作为启动时应该使用的配置文件

spring:
  profiles:
    active: test

创建一个application-test.yaml

server:
  port: 8888
servlet:
  session:
    timeout: 30m  #测试的话 需要长一些
config:
  key: TTTTT

创建一个application-dev.yaml

server:
  port: 7777
servlet:
  session:
    timeout: 30m  #测试的话 需要长一些
config:
  key: YYYYY

2. pom文件添加profiles

    <profiles>
        <profile>
            <id>
                dev
            </id>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

        </profile>
        <profile>
        <id>
            test
        </id>
        <properties>
            <spring.profiles.active>test</spring.profiles.active>
        </properties>
        </profile>
        <profile>
            <id>
                uat
            </id>
            <properties>
                <spring.profiles.active>uat</spring.profiles.active>
            </properties>
        </profile>
        
    </profiles>

3. sh脚本指定

.sh文件
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容