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

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

Introduction

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

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:br.com.poc.navigation.NavigationLoader.java

public static void main(String[] args) {

    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            ApplicationContextNavigation.class);

    NavigationLoader navigationLoader = new NavigationLoader();

    navigationLoader.setNavigationComponent(applicationContext.getBean(NavigationComponent.class));

    navigationLoader.startNavigation();//from   w ww  .j a  v a2 s  .  c  o  m

    applicationContext.close();

}

From source file:uk.ac.ebi.ep.parser.main.PathwaysParser.java

public static void main(String args[]) throws Exception {
    String file = "";
    String profile = "";

    if (args == null || args.length == 0) {
        System.out.println("Please provide required parameters");
        System.exit(0);/*from ww  w .  ja v  a 2s  .co m*/
    }

    if (args.length == 2) {

        profile = args[0];
        file = args[1];

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.getEnvironment().setActiveProfiles(profile);
        //context.scan("uk.ac.ebi.ep.data.dataconfig");
        context.scan("uk.ac.ebi.ep.data.dataconfig", "uk.ac.ebi.ep.parser.config");
        context.refresh();

        EnzymePortalPathwaysParser pathwaysParser = context.getBean(EnzymePortalPathwaysParser.class);

        pathwaysParser.parseReactomeFile(file);//Total time: 1:57:24.500s
    }

}

From source file:com.weib.soundsystem.CDPlayerMain.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext context = null;
    try {/*from ww  w. j  av a 2 s. c o m*/
        context = new AnnotationConfigApplicationContext(CDPlayerConfig.class);
        //            SgtPeppers sp = (SgtPeppers) context.getBean("sgtPeppers");
        //            sp.play();
        //            CDPlayer cdplayer = context.getBean(CDPlayer.class);
        //            cdplayer.play();

        WhiteAlbum cd = context.getBean(WhiteAlbum.class);
        CDPlayer cdplayer = context.getBean(CDPlayer.class, cd);
        cdplayer.play();

        //            CDPlayer cdwriter = (CDPlayer) context.getBean("cdWriter", (WhiteAlbum)context.getBean("whiteAlbum"));
        //            cdwriter.play();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (context != null) {
            context.close();
        }
    }
}

From source file:org.cloudfoundry.workers.stocks.integration.client.Main.java

public static void main(String args[]) throws Throwable {
    AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
    annotationConfigApplicationContext.getEnvironment().setActiveProfiles(isCloudFoundry() ? "cloud" : "local");
    annotationConfigApplicationContext.scan(ClientConfiguration.class.getPackage().getName());
    annotationConfigApplicationContext.refresh();

    StockClientGateway clientGateway = annotationConfigApplicationContext.getBean(StockClientGateway.class);
    Logger log = Logger.getLogger(Main.class.getName());
    String symbol = "VMW";
    StockSymbolLookup lookup = clientGateway.lookup(symbol);
    log.info("client: retrieved stock information: " + ToStringBuilder.reflectionToString(lookup));

}

From source file:com.searchbox.collection.oppfin.EENCollection.java

public static void main(String... args) throws JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            RootConfiguration.class);

    EENCollection collection = context.getBean(EENCollection.class);
    collection.synchronize();//from   w  w w  . j  a v  a 2  s.c o  m
}

From source file:org.schemaspy.Main.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger(Main.class.getName());

    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            "org.schemaspy.service");
    applicationContext.register(SchemaAnalyzer.class);

    if (argv.length == 1 && "-gui".equals(argv[0])) { // warning: serious temp hack
        new MainFrame().setVisible(true);
        return;/*  ww  w . j  a  v a  2  s  . co m*/
    }

    SchemaAnalyzer analyzer = applicationContext.getBean(SchemaAnalyzer.class);

    int rc = 1;

    try {
        rc = analyzer.analyze(new Config(argv)) == null ? 1 : 0;
    } catch (ConnectionFailure couldntConnect) {
        logger.log(Level.WARNING, "Connection Failure", couldntConnect);
        rc = 3;
    } catch (EmptySchemaException noData) {
        logger.log(Level.WARNING, "Empty schema", noData);
        rc = 2;
    } catch (InvalidConfigurationException badConfig) {
        logger.info("");
        if (badConfig.getParamName() != null)
            logger.log(Level.WARNING, "Bad parameter specified for " + badConfig.getParamName());
        logger.log(Level.WARNING, "Bad config " + badConfig.getMessage());
        if (badConfig.getCause() != null && !badConfig.getMessage().endsWith(badConfig.getMessage()))
            logger.log(Level.WARNING, " caused by " + badConfig.getCause().getMessage());

        logger.log(Level.FINE, "Command line parameters: " + Arrays.asList(argv));
        logger.log(Level.FINE, "Invalid configuration detected", badConfig);
    } catch (ProcessExecutionException badLaunch) {
        logger.log(Level.WARNING, badLaunch.getMessage(), badLaunch);
    } catch (Exception exc) {
        logger.log(Level.SEVERE, exc.getMessage(), exc);
    }

    System.exit(rc);
}

From source file:ru.develgame.jflickrorganizer.MainClass.java

public static void main(String args[]) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainClass.class);

    try {//from  w  w w .  jav  a2s .c o m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
    }

    context.getBean(LoginForm.class).setVisible(true);
}

From source file:io.lavagna.loader.Loader.java

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

    System.setProperty("datasource.dialect", "MYSQL");

    AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(TestServiceConfig.class,
            PersistenceAndServiceConfig.class);

    ac.register(CreateCardService.class);

    ProjectService ps = ac.getBean(ProjectService.class);
    CreateCardService ccs = ac.getBean(CreateCardService.class);

    UserRepository ur = ac.getBean(UserRepository.class);
    List<User> users = new ArrayList<>();

    System.out.println("creating users");
    for (int i = 0; i < 30; i++) {
        ur.createUser("loader", "user" + i, null, null, true);
        users.add(ur.findUserByName("loader", "user" + i));
    }/*  w  w w .j a  v a 2  s.  c o m*/
    System.out.println("end creation");

    CardLabelRepository clr = ac.getBean(CardLabelRepository.class);

    List<Project> projects = new ArrayList<>(PROJECT_NUMBERS);
    List<Integer> milestonesIds = new ArrayList<>();
    System.out.println("creating projects");
    for (int i = 0; i < PROJECT_NUMBERS; i++) {
        String name = "Load test project " + i;
        Project p = ps.create(name, "LDTEST_" + i, name);
        projects.add(p);

        // create user labels
        for (int iLabel = 0; iLabel < 10; iLabel++) {
            clr.addLabel(p.getId(), true, LabelType.NULL, LabelDomain.USER, "label-" + iLabel, 0);
        }

        // update milestone label
        CardLabel milestoneLabel = clr.findLabelByName(p.getId(), "MILESTONE", LabelDomain.SYSTEM);
        for (int j = 0; j < MILESTONES_PER_PROJECT; j++) {
            milestonesIds.add(clr.addLabelListValue(milestoneLabel.getId(), Integer.toString(j)).getId());
        }
    }
    System.out.println("end creation");

    System.out.println("creating boards");
    for (Project project : projects) {
        buildBoards(project, ac, users, milestonesIds);
    }
    System.out.println("end creation");

    long processed = ccs.getCreatedCardCounter().get();
    while (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
        long current = ccs.getCreatedCardCounter().get();
        System.err.println("processed: " + (current - processed) + " cards in 10s");
        processed = current;
    }

    ac.close();
}

From source file:com.searchbox.collection.oppfin.TopicCollection.java

public static void main(String... args) throws JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, JobParametersInvalidException, SAXException, IOException {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RootConfiguration.class,
            TopicCollection.class);

    TopicCollection collection = context.getBean(TopicCollection.class);

    collection.synchronize();/*w  w w.j a  v  a  2s . c o m*/
}

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")));
                    }/*ww  w  .j  a v  a2 s. c  om*/
                    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();
                }
            }
        }
    }
}