Example usage for org.springframework.boot SpringApplication addInitializers

List of usage examples for org.springframework.boot SpringApplication addInitializers

Introduction

In this page you can find the example usage for org.springframework.boot SpringApplication addInitializers.

Prototype

public void addInitializers(ApplicationContextInitializer<?>... initializers) 

Source Link

Document

Add ApplicationContextInitializer s to be applied to the Spring ApplicationContext .

Usage

From source file:com.ericsson.eiffel.remrem.publish.cli.CLI.java

public static void main(String args[]) {
    SpringApplication application = new SpringApplication(CLI.class);
    application.addInitializers(new SpringLoggingInitializer());
    application.setBannerMode(Banner.Mode.OFF);
    application.setLogStartupInfo(false);
    application.setWebEnvironment(false);
    CliOptions.parse(args);// w  w  w  .  ja  v  a2 s  .  c om
    application.run(args);
}

From source file:com.devnexus.ting.DevNexusApplication.java

public static void main(String[] args) throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    final SpringApplication application = new SpringApplication(DevNexusApplication.class);
    application.addInitializers(new DefaultApplicationContextInitializer());
    application.run(args);/*from w  ww .j  av  a  2  s.  c  om*/
}

From source file:com.ericsson.eiffel.remrem.generate.cli.CLI.java

public static void main(String[] args) throws Exception {
    SpringApplication application = new SpringApplication(CLI.class);
    application.addInitializers(new SpringLoggingInitializer());
    application.setBannerMode(Banner.Mode.OFF);
    application.setLogStartupInfo(false);
    application.setWebEnvironment(false);
    CLIOptions.parse(args);/*from   www . j  a va2  s .c om*/
    application.run(args);
}

From source file:cf.spring.config.YamlPropertyContextInitializerTest.java

@Test
public void contextWithYamlProperties() {
    final String name = "config";

    final SpringApplication springApplication = new SpringApplication(Config.class);
    springApplication.addInitializers(new YamlPropertyContextInitializer(name, "config", "testProperties.yml"));
    try (ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) springApplication
            .run()) {//from  w ww.j a  va 2s. c  o m
        final YamlDocument config = applicationContext.getBean(name, YamlDocument.class);
        assertNotNull(config);
        assertEquals(config.get("foo"), "This is foo");

        final Environment environment = applicationContext.getEnvironment();
        assertEquals(environment.getProperty("foo"), "This is foo");
    }
}

From source file:cf.spring.config.YamlPropertyContextInitializerTest.java

@Test(dependsOnMethods = "contextWithYamlProperties")
public void contextWithAlternateYamlProperties() {
    final String property = "config";
    final String name = "alternate";

    System.setProperty(property, "alternateConfig.yml");

    final SpringApplication springApplication = new SpringApplication(Config.class);
    springApplication.addInitializers(new YamlPropertyContextInitializer(name, property, "testProperties.yml"));
    try (ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) springApplication
            .run()) {//from ww  w  . java2  s.co m
        final YamlDocument config = applicationContext.getBean(name, YamlDocument.class);
        assertNotNull(config);
        assertEquals(config.get("foo"), "bar");
    }
}

From source file:org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.java

private void registerTargetContext(C targetContext, SpringApplication builder) {
    if (targetContext != null) {
        builder.addInitializers(new ApplicationContextInitializer<ConfigurableApplicationContext>() {
            @SuppressWarnings("unchecked")
            @Override/*from   w w  w  . j  a  va2s  . c om*/
            public void initialize(ConfigurableApplicationContext applicationContext) {
                ((GenericApplicationContext) applicationContext).registerBean(TARGET_EXECUTION_CTX_BEAN_NAME,
                        (Class<C>) targetContext.getClass(), (Supplier<C>) () -> targetContext);
            }
        });
    }
}

From source file:ubicrypt.UbiCrypt.java

@Override
public void start(final Stage stage) throws Exception {
    setUserAgentStylesheet(STYLESHEET_MODENA);
    stage.setTitle("UbiCrypt");
    anchor().setStage(stage);//from   ww  w.  j ava 2s  . co m
    try {
        final PGPKeyPair kp = encryptionKey();
        encrypt(Collections.singletonList(kp.getPublicKey()),
                new ByteArrayInputStream(StringUtils.repeat("ciao", 1).getBytes()));
    } catch (Exception e) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Strong Encryption Required");
        alert.setHeaderText("Install JCE Unlimited Strength Jurisdiction policy files");
        alert.setContentText(
                "You can install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files, which are required to use strong encryption.\n"
                        + "Download the files and instructions for Java 8.\n"
                        + "Locate the jre\\lib\\security directory for the Java instance that the UbiCrypt is using.\n"
                        + "For example, this location might be: C:\\Program Files\\Java\\jre8\\lib\\security.\n"
                        + "Replace these two files with the .jar files included in the JCE Unlimited Strength Jurisdiction Policy Files download.\n"
                        + "Stop and restart the UbiCrypt.\n\n\n\n\n\n");
        ButtonType icePage = new ButtonType("Go to JCE download Page");
        alert.getButtonTypes().addAll(icePage);
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == icePage) {
            getHostServices().showDocument(
                    "http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html");
        }
        Platform.exit();
    }
    final File secFile = securityFile().toFile();
    stage.setScene(anchor().show(secFile.exists() ? "login" : "createKey", getHostServices()));
    stage.show();
    final UbiCrypt ubiCrypt = this;
    anchor().getPasswordStream().subscribeOn(Schedulers.io()).subscribe(pwd -> {
        final SpringApplication app = new SpringApplication(UbiConf.class, PathConf.class, UIConf.class);
        app.setRegisterShutdownHook(false);
        app.addInitializers(new FixPassPhraseInitializer(pwd));
        app.setLogStartupInfo(true);
        ctx = app.run();
        ctx.getAutowireCapableBeanFactory().autowireBean(ubiCrypt);
        ctx.getBeanFactory().registerSingleton("stage", stage);
        ctx.getBeanFactory().registerSingleton("hostService", getHostServices());
        ctx.getBeanFactory().registerSingleton("osUtil", new OSUtil(getHostServices()));
        ControllerFactory cfactory = new ControllerFactory(ctx);
        StackNavigator navigator = new StackNavigator(null, "main", cfactory);
        stage.setScene(new Scene(navigator.open()));
    });

    stage.setOnCloseRequest(windowEvent -> shutdown.run());
    Runtime.getRuntime().addShutdownHook(new Thread(shutdown));
}