SpringBoot 分环境打包


SpringBoot 分环境打包

application.yml文件配置

spring:
  profiles:
    # 动态环境选择,对应pom.xml文件中 <properties> <env>devenv> properties>
    active: @env@

pom.xml 文件配置

<profiles>
    <profile>
        
        <id>devid>
        
        <properties>
            <env>devenv>
        properties>
        <activation>
            
            <activeByDefault>trueactiveByDefault>
        activation>
    profile>

    <profile>
        <id>testid>
        <properties>
            <env>testenv>
        properties>
    profile>

    <profile>
        <id>prodid>
        <properties>
            <env>prodenv>
        properties>
    profile>
profiles>

打包测试

#使用命令打包
mvn package # 打包

#或者使用IDEA工具打包

启动jar

#打包没有选择环境可以使用参数直接指定环境
java -jar fei-0.0.1-SNAPSHOT.jar
java -jar fei-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod
java -jar fei-0.0.1-SNAPSHOT.jar --server.port=8072 --spring.profiles.active=prod

nohup java -jar java -jar fei-0.0.1-SNAPSHOT.jar > ./fei-8072.out 2>&1 &
nohup java -jar java -jar fei-0.0.1-SNAPSHOT.jar > ./fei-8072.out 2>&1 &

ps -aux | grep java