环境

JHipster定义了两个环境 Spring profiles :

  • dev 对于开发:它关注于开发的易用性和生产力
  • prod 对于生产:它关注性能和可扩展性

这些配置文件有两种不同的配置:

  • The Maven/Gradle profiles are used at build time. For example ./mvnw -Pprod package or ./gradlew bootWar -Pprod will package a production application.
  • The Spring profiles work at run time. Some Spring beans will behave differently, depending on the profile.

Spring profiles are set by Maven/Gradle, so we have a consistency between the two methods: you will have a prod profile on Maven/Gradle and Spring at the same time.

Note: Spring profiles are used to configure the JHipster application properties, so you should be interested in reading our common application properties documentation.

By default, JHipster will use the dev profile

If you run the application without Maven/Gradle, launch the “Application” class (you can probably run it easily from your IDE by right-clicking on it).

If you run the application with Maven, run ./mvnw to use our Maven Wrapper, or mvn to use your own Maven installation.

If you run the application with Gradle, run ./gradlew to use our Gradle Wrapper, or gradle to use your own Gradle installation.

When using Angular 2+ if you need to do a clean run with webpack compilation enabled for dev profile you can pass the webpack param as below

./mvnw -Pdev,webpack or ./gradlew -Pdev -Pwebpack

In production, JHipster has to run with the prod profile

You can run JHipster in production directly using Maven or Gradle:

  • With Maven, run ./mvnw -Pprod (or mvn -Pprod)
  • With Gradle, run ./gradlew -Pprod (or gradle -Pprod)

If you want to package your application as an executable WAR file, you should provide Maven or Gradle with a profile. E.g.,:

  • With Maven, run ./mvnw -Pprod package (or mvn -Pprod package)
  • With Gradle, run ./gradlew -Pprod bootWar (or gradle -Pprod bootWar)

When you run your production application from a WAR file, the default is to use the same profile(s) as used during packaging. If you want to override this, you can explicitly provide an alternative in VM argument:

  • ./java -jar jhipster-0.0.1-SNAPSHOT.war --spring.profiles.active=...

Spring profiles switches

JHipster comes with three additional profiles used as switches:

These can be used along with both the dev and prod profiles. Please note that by default, the swagger profile is disabled in prod and enabled in dev by setting the spring.profiles.include property in application.yml.

swagger, no-liquibase, tls are only used at runtime:

  • In your IDE, run your main application class with spring.profiles.active=dev,no-liquibase (please note you need to include the dev or prod profile explicitly)
  • With a packaged application: ./java -jar jhipster-0.0.1-SNAPSHOT.war --spring.profiles.active=prod,no-liquibase

With Maven, you can also use those profiles directly:

  • ./mvnw -Pprod,swagger,no-liquibase
  • ./mvnw -Pdev,no-liquibase

With Gradle, you can also use those profiles directly:

  • ./gradlew -Pprod -Pswagger -Pno-liquibase
  • ./gradlew -Pno-liquibase