Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Created August 4, 2023 02:53
Show Gist options
  • Save sandipchitale/e4952000b89d6bb9eec2e338a44d9807 to your computer and use it in GitHub Desktop.
Save sandipchitale/e4952000b89d6bb9eec2e338a44d9807 to your computer and use it in GitHub Desktop.
Running as War or Standalone Springboot App #springboot #war #notwar
@Bean
@ConditionalOnWebApplication
@ConditionalOnNotWarDeployment()
public CommandLineRunner clrNotInWar() {
return (args) -> {
System.out.println("Not running as war!");
};
}
static class OnWarDeployment extends NoneNestedConditions {
OnWarDeployment() {
super(ConfigurationPhase.REGISTER_BEAN);
}
@ConditionalOnNotWarDeployment()
static class OnWar{}
}
@Bean
@ConditionalOnWebApplication
@Conditional(OnWarDeployment.class)
public CommandLineRunner clrOnWar() {
return (args) -> {
System.out.println("Running as war!");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment