Skip to content

Instantly share code, notes, and snippets.

@ghsatpute
Created June 16, 2020 13:35
Show Gist options
  • Save ghsatpute/42b036aa7ef2acb1d64f313a6ee38fd8 to your computer and use it in GitHub Desktop.
Save ghsatpute/42b036aa7ef2acb1d64f313a6ee38fd8 to your computer and use it in GitHub Desktop.
Spring Profiles via Maven

While building the package set the profile

 $ mvn -Pdev clean install

When the jar is built you can simply run by

$ java -jar target/<your jar name>.jar

You'll see output as below

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.6.RELEASE)

2020-06-16 18:57:05.439  INFO [,,,] 18128 --- [           main] com.teradata.baas.api.ApiApplication     : The following profiles are active: dev
2020-06-16 18:57:07.162  INFO [,,,] 18128 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-06-16 18:57:07.339  INFO [,,,] 18128 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 162ms. Found 4 JPA repository interfaces.

As you can see in the first line, now the default profile for jar is set as dev

...
spring.profiles.active = @spring.profiles.active@
...
...
<profiles>
<profile>
<id>default</id>
<properties>
<activatedProperties>default</activatedProperties>
<spring.profiles.active>default</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment