Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext AnnotationConfigApplicationContext.

Prototype

public AnnotationConfigApplicationContext() 

Source Link

Document

Create a new AnnotationConfigApplicationContext that needs to be populated through #register calls and then manually #refresh refreshed .

Usage

From source file:org.jmangos.auth.AuthServer.java

/**
 * The main method./*from   ww w.j av  a2s  .c o  m*/
 * 
 * @param args
 *            the arguments
 * @throws Exception
 *             the exception
 */
public static void main(final String[] args) throws Exception {

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan("org.jmangos.commons", "org.jmangos.auth");
    context.refresh();
    ServiceContent.setContext(context);
    context.getBean(NetworkService.class).start();
}

From source file:uk.ac.ebi.ep.sitemap.main.SiteMapMain.java

public static void main(String... args) throws Exception {

    //////////////comment here ///////////////////////
    //        args = new String[4];
    //        //String dbConfig = "ep-mm-db-enzdev";
    //        //String dbConfig = "ep-mm-db-enzprel";
    //        String userHome = System.getProperty("user.home");
    //        String filename = "SiteMap";
    //        String testing = "true";
    //        //from w  w  w.java 2s.c  o m
    //               
    //        args[0] = "vezpdev";
    //        args[1] = userHome;
    //        args[2] = filename;
    //        args[3] = testing;
    //////////////uncomment for testing parameters only ///////////////////////          
    if (args == null) {
        System.out.println("Please provide required parameters");
        System.exit(0);
    }

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.getEnvironment().setActiveProfiles(args[0]);
    context.scan("uk.ac.ebi.ep.data.dataconfig");
    context.refresh();

    UniprotEntryService service = context.getBean(UniprotEntryService.class);

    SiteMapGenerator siteMapGenerator = new EnzymePortalSiteMap(service);
    boolean testMode = Boolean.parseBoolean(args[3]);
    siteMapGenerator.generateSitemap(args[1], args[2], testMode);

}

From source file:org.jmangos.realm.RealmServer.java

/**
 * The main method.//w ww.  ja va  2s. c o  m
 * 
 * @param args
 *            the arguments
 */
public static void main(final String[] args) {

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.scan("org.jmangos.commons", "org.jmangos.world", "org.jmangos.realm");
    context.refresh();
    ServiceContent.setContext(context);
    context.getBean(NetworkService.class).start();

    console.setVariable("applicationContext", context);
    console.setVariable("itemStorage", context.getBean(ItemStorages.class));
    // console.run();
}

From source file:fr.kissy.hellion.server.Main.java

public static void main(String[] args) throws InterruptedException {
    context = new AnnotationConfigApplicationContext();
    context.register(ApplicationConfig.class);
    context.scan("fr.kissy.hellion.server.repository");
    context.refresh();//  w ww  .j a v  a  2s.c  o m
}

From source file:org.dawnsci.marketplace.MarketplaceApplication.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    // convert the command line argument to properties
    CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource(args);
    ctx.getEnvironment().getPropertySources().addFirst(ps);
    ctx.register(ApplicationConfiguration.class);
    ctx.refresh();/*from   ww w. j  ava 2 s .  c o  m*/
    try {
        SpringApplication.run(MarketplaceApplication.class, args);
    } finally {
        ctx.close();
    }
}

From source file:com.tcloud.bee.key.server.jetty.SpringJettyServer.java

/**
 * @param args/*from  w ww  .  j  a  v a2 s .  c  o m*/
 */
public static void main(String[] args) {

    logger.info("Start Spring Jetty Server.....");

    try {

        @SuppressWarnings("resource")
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        /*
         * One problem with SpringMVC is it creates its own application
         * context, and so it can end up failing but our application will
         * keep running.
         * 
         * To detect the case where the SpringMVC's web application context
         * fails we'll listen for ContextRefreshEvents and set a flag when
         * we see one.
         */
        applicationContext.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() {
            @Override
            public void onApplicationEvent(ContextRefreshedEvent event) {
                ApplicationContext ctx = event.getApplicationContext();
                if (ctx instanceof AnnotationConfigWebApplicationContext) {
                    webApplicationContextInitialized = true;
                }
            }
        });

        logger.info("Start register JettyConfiguration.....");
        applicationContext.registerShutdownHook();
        applicationContext.register(RootConfiguration.class);
        applicationContext.refresh();

        if (!webApplicationContextInitialized) {
            logger.error("Web application context not initialized. Exiting.");
            System.exit(1);
        }

        logger.info("Running.");
    } catch (Exception e) {
        logger.error("Error starting application", e);
        System.exit(1);
    }
}

From source file:ca.unx.template.Main.java

public static void main(String[] args) throws Exception {

    final Logger logger = LoggerFactory.getLogger("main");

    try {//from  ww  w .ja va  2  s .  co  m
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        /*
         * One problem with SpringMVC is it creates its own application
         * context, and so it can end up failing but our application will
         * keep running.
         * 
         * To detect the case where the SpringMVC's web application context
         * fails we'll listen for ContextRefreshEvents and set a flag when
         * we see the web application context refresh.
         */
        applicationContext.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() {
            @Override
            public void onApplicationEvent(ContextRefreshedEvent event) {
                ApplicationContext ctx = event.getApplicationContext();
                if (ctx instanceof GenericWebApplicationContext) {
                    webApplicationContextInitialized = true;
                }
            }
        });

        applicationContext.registerShutdownHook();
        applicationContext.register(RootConfiguration.class);
        applicationContext.refresh();

        if (!webApplicationContextInitialized) {
            logger.error("Failed to initialize web application.  Exiting.");
            System.exit(1);
        }

        logger.info("Running.");
    } catch (Exception e) {
        logger.error("Error starting application", e);
        System.exit(1);
    }
}

From source file:piecework.client.LoadTester.java

public static final void main(String[] args) throws Exception {
    String profile = args.length > 0 ? args[0] : "workstation";

    StandardEnvironment environment = new StandardEnvironment();
    environment.setActiveProfiles(profile);
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.setEnvironment(environment);//from   www  .  j a v a2s. co m
    ctx.register(ClientConfiguration.class);
    ctx.refresh();

    KeyManagerCabinet cabinet = ctx.getBean(KeyManagerCabinet.class);
    SecuritySettings securitySettings = ctx.getBean(SecuritySettings.class);

    LoadTester loadTester = new LoadTester(cabinet.getKeystore(), securitySettings);
    loadTester.retrieveAllTasks();
}

From source file:uk.ac.kcl.Main.java

public static void main(String[] args) {
    File folder = new File(args[0]);
    File[] listOfFiles = folder.listFiles();
    assert listOfFiles != null;
    for (File listOfFile : listOfFiles) {
        if (listOfFile.isFile()) {
            if (listOfFile.getName().endsWith(".properties")) {
                System.out.println("Properties sile found:" + listOfFile.getName()
                        + ". Attempting to launch application context");
                Properties properties = new Properties();
                InputStream input;
                try {
                    input = new FileInputStream(listOfFile);
                    properties.load(input);
                    if (properties.getProperty("globalSocketTimeout") != null) {
                        TcpHelper.setSocketTimeout(
                                Integer.valueOf(properties.getProperty("globalSocketTimeout")));
                    }// w  w w .  ja  va  2  s .  c  o  m
                    Map<String, Object> map = new HashMap<>();
                    properties.forEach((k, v) -> {
                        map.put(k.toString(), v);
                    });
                    ConfigurableEnvironment environment = new StandardEnvironment();
                    MutablePropertySources propertySources = environment.getPropertySources();
                    propertySources.addFirst(new MapPropertySource(listOfFile.getName(), map));
                    @SuppressWarnings("resource")
                    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
                    ctx.registerShutdownHook();
                    ctx.setEnvironment(environment);
                    String scheduling;
                    try {
                        scheduling = properties.getProperty("scheduler.useScheduling");
                        if (scheduling.equalsIgnoreCase("true")) {
                            ctx.register(ScheduledJobLauncher.class);
                            ctx.refresh();
                        } else if (scheduling.equalsIgnoreCase("false")) {
                            ctx.register(SingleJobLauncher.class);
                            ctx.refresh();
                            SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class);
                            launcher.launchJob();
                        } else if (scheduling.equalsIgnoreCase("slave")) {
                            ctx.register(JobConfiguration.class);
                            ctx.refresh();
                        } else {
                            throw new RuntimeException(
                                    "useScheduling not configured. Must be true, false or slave");
                        }
                    } catch (NullPointerException ex) {
                        throw new RuntimeException(
                                "useScheduling not configured. Must be true, false or slave");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:lab.example.service.LotteryService.java

public static void main(String[] args) throws Exception {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(LotteryService.class);

    SpringApplication application = new SpringApplication(LotteryService.class);

    application.setApplicationContextClass(AnnotationConfigApplicationContext.class);
    SpringApplication.run(LotteryService.class, args);
}