[英]jhipster Unable to change spring run profile to prod - always starts with dev,swagger - Maven as Service
I am doing我在做
./mvnw -Pprod clean verify
And starts as dev and not has prod profile.并以 dev 开头,没有 prod 配置文件。
Do I have to change something in my pom file?我是否必须更改我的 pom 文件中的某些内容?
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>target/classes/static/</directory>
</fileset>
</filesets>
</configuration>
</plugin>
To set as a service in a debian server I do:要在 debian 服务器中设置为服务,我会:
sudo chmod +x /var/lib/nms-api/n2.jar
sudo chown nmsapi:nmsapi /var/lib/nms-api/n1.jar
sudo ln -s /var/lib/nms-api/n2.jar /etc/init.d/nms2
sudo systemctl enable nms2
sudo service nms2 start
Edit编辑
I am using jhipster framework https://www.jhipster.tech/production/ they say:我正在使用 jhipster 框架https://www.jhipster.tech/production/他们说:
Please note that this JAR file uses the profile we selected when building it.
请注意,此 JAR 文件使用我们在构建时选择的配置文件。 As it was built using the prod file in the previous section, it will therefore run with the prod profile.
由于它是使用上一节中的 prod 文件构建的,因此它将使用 prod 配置文件运行。
and the ps -aux
says:和
ps -aux
说:
/usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n1.jar
Is there a way to set java -Dspring.profiles.active=prod
in the line above when staring as a service?当作为服务盯着看时,有没有办法在上面的行中设置
java -Dspring.profiles.active=prod
?
Edit 2编辑 2
I set the Environment Variable我设置环境变量
sudo -i
root@nms-cp01-vm01:~# export SPRING_PROFILES_ACTIVE=prod
and和
cat /etc/environment
$ sudo vi /etc/environment
$ echo $SPRING_PROFILES_ACTIVE
prod
$ sudo echo $SPRING_PROFILES_ACTIVE
prod
And can run in prod profile if并且可以在 prod 配置文件中运行,如果
/usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n4test.jar
and not in prod profile, but in dev if run as root而不是在 prod 配置文件中,但如果以 root 身份运行,则在 dev 中
sudo /usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n4test.jar
You are confusing maven profiles and spring boot profiles.您混淆了 maven 配置文件和 spring 引导配置文件。 They are two totally separate concepts.
它们是两个完全不同的概念。 Maven profiles are flags for turning on specific steps during building, whereas a spring profile is a runtime flag to tell spring which set of configuration to apply.
Maven 配置文件是用于在构建期间打开特定步骤的标志,而 spring 配置文件是运行时标志,用于告诉 spring 应用哪组配置。 For mor information on spring profiles you can see here
有关 spring 配置文件的更多信息,您可以在此处查看
Spring profiles can be set through systen properties, environment variables, but also part of your maven build. Spring 配置文件可以通过系统属性、环境变量进行设置,但也是 maven 构建的一部分。 The first two are much more flexible imo.
前两个在 imo 中要灵活得多。
System properties系统属性
java -Dspring.profiles.active=prod
Environmebt Variables环境变量
export SPRING_PROFILES_ACTIVE=prod
As Part of a Maven Build profile作为 Maven 构建配置文件的一部分
<profiles>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
<!-- The rest of your profile here -->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
</profile>
</profiles>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.