簡體   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