繁体   English   中英

jhipster 无法将 spring 运行配置文件更改为 prod - 始终以 dev、swagger 开头 - Maven 作为服务

[英]jhipster Unable to change spring run profile to prod - always starts with dev,swagger - Maven as Service

我在做

./mvnw -Pprod clean verify

并以 dev 开头,没有 prod 配置文件。

我是否必须更改我的 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>

要在 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

编辑

我正在使用 jhipster 框架https://www.jhipster.tech/production/他们说:

请注意,此 JAR 文件使用我们在构建时选择的配置文件。 由于它是使用上一节中的 prod 文件构建的,因此它将使用 prod 配置文件运行。

ps -aux说:

/usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n1.jar

当作为服务盯着看时,有没有办法在上面的行中设置java -Dspring.profiles.active=prod

编辑 2

我设置环境变量

sudo -i
root@nms-cp01-vm01:~# export SPRING_PROFILES_ACTIVE=prod

 cat /etc/environment 
$ sudo vi /etc/environment 
$ echo $SPRING_PROFILES_ACTIVE
prod
$ sudo echo $SPRING_PROFILES_ACTIVE
prod

并且可以在 prod 配置文件中运行,如果

 /usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n4test.jar 

而不是在 prod 配置文件中,但如果以 root 身份运行,则在 dev 中

sudo /usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/nms-api/n4test.jar 

您混淆了 maven 配置文件和 spring 引导配置文件。 它们是两个完全不同的概念。 Maven 配置文件是用于在构建期间打开特定步骤的标志,而 spring 配置文件是运行时标志,用于告诉 spring 应用哪组配置。 有关 spring 配置文件的更多信息,您可以在此处查看

Spring 配置文件可以通过系统属性、环境变量进行设置,但也是 maven 构建的一部分。 前两个在 imo 中要灵活得多。

系统属性

java -Dspring.profiles.active=prod

环境变量

export SPRING_PROFILES_ACTIVE=prod

作为 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM