Skip to content

Instantly share code, notes, and snippets.

@willmitchell
Created September 20, 2014 21:14
Show Gist options
  • Save willmitchell/d1c700086dc5799958ea to your computer and use it in GitHub Desktop.
Save willmitchell/d1c700086dc5799958ea to your computer and use it in GitHub Desktop.
What the JHipster Application looks like.
@ComponentScan
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
public class Application {
private final Logger log = LoggerFactory.getLogger(Application.class);
@Inject
private Environment env;
/**
* Initializes pr.
* <p/>
* Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile
* <p/>
*/
@PostConstruct
public void initApplication() throws IOException {
if (env.getActiveProfiles().length == 0) {
log.warn("No Spring profile configured, running with default configuration");
} else {
log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
}
}
/**
* Main method, used to run the application.
*
* To run the application with hot reload enabled, add the following arguments to your JVM:
* "-javaagent:spring_loaded/springloaded-jhipster.jar -noverify -Dspringloaded=plugins=io.github.jhipster.loaded.instrument.JHipsterLoadtimeInstrumentationPlugin"
*/
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setShowBanner(false);
SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
// Check if the selected profile has been set as argument.
// if not the development profile will be added
addDefaultProfile(app, source);
app.run(args);
}
/**
* Set a default profile if it has not been set
*/
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) {
if (!source.containsProperty("spring.profiles.active")) {
app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment