简体   繁体   English

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

[英]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.

相关问题 使用开发人员配置文件而不是产品的JHipster可执行WAR - JHipster executable WAR using dev profile instead of prod 如果prod配置文件不存在,则Spring Boot 2使用dev配置文件 - Spring Boot 2 use dev profile if prod profile is not exist 弹簧负载产品简介 - Spring load prod profile JHipster Docker Build with dev,swagger,no-liquibase - JHipster Docker Build with dev,swagger,no-liquibase 无法使用开发人员配置文件在Eclipse中运行jhipster-registry,需要Git回购 - Can't run jhipster-registry in Eclipse with dev profile, needs Git repo jhipster-将应用程序部署到Heroku后无法运行本地开发人员配置文件 - jhipster - can't run local dev profile after deploying app to Heroku 在开发和生产中选择 oracle db 后 JHipster liquibase 未准备好 - JHipster liquibase not ready after choosing oracle db in dev & prod 在产品概要文件中构建JHipster应用程序时无法处理请求 - Request cannot be processed when building JHipster application in prod profile 根据logback-spring.xml中的springProfiles [dev,stg,prod],如何激活在命令行中传递的相应spring概要文件 - Depending on springProfiles[dev, stg, prod] in logback-spring.xml , how to activate corresponding spring profile passed in command line 使用 Spring 配置文件和 Maven 配置文件 - Using Spring profile and Maven Profile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM