通过在Vm参数中加: -Dspring.profiles.active=dev 来指定当前环境的配置文件

idea 详细配置过程见 构建教程.mp4

1
2

mvn clen install -Dspring.profiles.active=dev

deploy

1. maven 插件配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<!-- 启动类-->
<mainClass>com.xmx.XmxBaseApplication</mainClass>
<executable>true</executable>

</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

2. linux 系统配置自启动

查看更多spring boot 项目部署方式

以下过程适用于 centos系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# Copy the contents
[Unit]
Description=Xmx Base Service
After=syslog.target

[Service]
Environment='JAVA_OPTS=-Dspring.profiles.active=dev' # 环境变量
# 可执行jar的路径
ExecStart=/usr/local/im/xmx.com/packs/xmx.base.jar ${JAVA_OPTS}
SuccessExitStatus=143
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
# Copy here end ==========

vim /etc/systemd/system/xmx.base.service

systemctl enable xmx.base.service

# laster start app

systemctl start xmx.base

关于 systemctl

经过上述过程后,可以通过以下命令进行操作

1
2
3
4
5
6
7
8
9
10
11
# start
systemctl start app

# stop
systemctl stop app

# restart
systemctl restart app

# status
systemctl status app

请参考:

Systemd 入门教程:实战篇