Example usage for org.springframework.boot.builder SpringApplicationBuilder headless

List of usage examples for org.springframework.boot.builder SpringApplicationBuilder headless

Introduction

In this page you can find the example usage for org.springframework.boot.builder SpringApplicationBuilder headless.

Prototype

public SpringApplicationBuilder headless(boolean headless) 

Source Link

Document

Sets if the application is headless and should not instantiate AWT.

Usage

From source file:com.github.bfour.fpliteraturecollector.application.Application.java

public static void main(String[] args) {

    try {//w w w.  java  2  s . co m

        // https://vvirlan.wordpress.com/2014/12/10/solved-caused-by-java-awt-headlessexception-when-trying-to-create-a-swingawt-frame-from-spring-boot/
        SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
        builder.headless(false);
        ConfigurableApplicationContext context = builder.run(args);

        // Neo4jResource myBean = context.getBean(Neo4jResource.class);
        // myBean.functionThatUsesTheRepo();

        // ServiceManager servMan = ServiceManager
        // .getInstance(ServiceManagerMode.TEST);
        ServiceManager servMan = context.getBean(ServiceManager.class);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(servMan,
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);

        FPJGUIManager.getInstance().initialize();

        MainWindow.getInstance(servMan).setVisible(true);

    } catch (BeanCreationException e) {
        e.printStackTrace();
        if (ExceptionUtils.getRootCause(e) instanceof IOException)
            ApplicationErrorDialogue.showMessage("Sorry, could not access the database.\n"
                    + "This might be because it is currently in use or because there are insufficient access rights.\n"
                    + "Try closing all running instances of this application and restart.");
        else
            ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL);
    } catch (Exception e) {
        e.printStackTrace();
        ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL);
    }

}

From source file:ninja.eivind.hotsreplayuploader.Client.java

@Override
public void init() {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Client.class);
    context = builder.headless(false).run(launchArgs);
    context.getAutowireCapableBeanFactory().autowireBean(this);

    //add a shutdown hook to be really sure, resources are closed properly
    Runtime.getRuntime().addShutdownHook(new Thread(context::close));
}