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 <T> T getBean(String name, Class<T> requiredType) throws BeansException 

Source Link

Usage

From source file:pieShareAppITs.helper.runner.FileCreatingBot.java

/**
 * @param args the command line arguments
 *///from w  w  w.j  a v  a  2 s .co m
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = BotUtil.login(args);

    PieUser user = context.getBean("pieUser", PieUser.class);
    PieShareConfiguration config = user.getPieShareConfiguration();

    File filex = new File(config.getWorkingDir().getParent(), "test.txt");
    TestFileUtils.createFile(filex, 2);
    File fileMain = new File(config.getWorkingDir(), "test.txt");

    FileUtils.moveFile(filex, fileMain);
}

From source file:org.my.spring.batch.java.config.demo.Main.java

public static void main(String[] args) {
    //System.exit(SpringApplication.exit(SpringApplication.run(MyBatchConfiguration.class, args)));
    logger.log(Level.INFO, "extracting  job parameters from command line arguments {0}", args);
    JobParameters jobParameters = parseJobParameters(args);
    String basePackage = Main.class.getPackage().getName();
    logger.log(Level.INFO, "scanning {0} for classes with bean definitions", basePackage);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(basePackage);
    Job job1 = context.getBean("job1", Job.class);
    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    try {/*from   w w w . j  av  a 2s .  co  m*/
        JobExecution jobExecution = jobLauncher.run(job1, jobParameters);
        logger.log(Level.INFO, "job execution {0} ended with status: {1}",
                new Object[] { jobExecution.getId(), jobExecution.getStatus() });
    } catch (Exception ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}

From source file:eu.trentorise.game.Application.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(AppConfig.class);
    ctx.register(MongoConfig.class);
    ctx.refresh();/*from   ww w. ja va 2s . c o m*/
    Workflow gameWorkflow = ctx.getBean("workflow", Workflow.class);

    /**
     * input map known fields
     * 
     * bikeDistance walkDistance busDistance trainDistance carDistance ->
     * double , distances must be expressed in km
     * 
     * bikeSharing -> boolean
     * 
     * park -> park id
     * 
     * sustainable -> boolean
     * 
     * p+r -> boolean
     * 
     * 
     * 
     */

    Map<String, Object> data = new HashMap<String, Object>();
    // data.put("bikeDistance", 8.43);
    // data.put("walkDistance", 3.100);
    // data.put("carDistance", 0.00);
    // data.put("busDistance", 0.00);
    // data.put("bikesharing", true);
    // data.put("sustainable", true);
    // data.put("p+r", true);
    // data.put("park", "MANIFATTURA");
    gameWorkflow.apply("demo-game", "save_itinerary", "1", data, null);
}

From source file:com.springsource.html5expense.config.BatchConfig.java

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

    AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(
            BatchConfig.class);

    Job job = annotationConfigApplicationContext.getBean("read-eligible-charges", Job.class);

    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("file", "foo");
    builder.addLong("uid", System.currentTimeMillis());
    JobParameters jobParameters = builder.toJobParameters();

    JobLauncher jobLauncher = annotationConfigApplicationContext.getBean(JobLauncher.class);
    jobLauncher.run(job, jobParameters);

}

From source file:com.home.ln_spring.ch5.profile.ProfileJavaConfigExample.java

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

    context.getEnvironment().setActiveProfiles("highschool");
    context.register(KindergartenConfig.class, HighschoolConfig.class);
    context.refresh();//from  w  w w .  java  2  s .  c o  m

    FoodProviderService foodProviderService = context.getBean("foodProviderService", FoodProviderService.class);

    List<Food> lunchSet = foodProviderService.provideLunchSet();

    for (Food food : lunchSet) {
        System.out.println("Food: " + food.getName());
    }
}

From source file:com.mycompany.swing2explore.views.NewMain.java

/**
 * @param args the command line arguments
 */// w w w.j av a  2s .c o m
public static void main(String[] args) {
    //ctx = new AnnotationConfigApplicationContext(PersistenceJPAConfig.class);
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(PersistenceJPAConfig.class);
    //ctx.scan("com.mycompany.swing2explore");
    ctx.refresh();
    System.out.println("main is ok");
    // TODO code application logic here
    PersonView personView = ctx.getBean("personViewController", PersonView.class);
    personView.personView();
    personView.pesan("ini adalah pesan untuk service");
}

From source file:io.github.carlomicieli.springbooks.MainClass.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ApplicationConfig.class);
    //        ctx.getEnvironment().setActiveProfiles("default");
    //        ctx.register(ApplicationConfig.class);
    //        ctx.refresh();

    log.info("Running sample application...");
    InitService s = ctx.getBean("initService", InitService.class);

    log.info("Dropping books collection...");
    s.dropBooks();//w  ww.  jav  a2  s .co  m

    log.info("Init books collection...");
    s.initBooks();

    BookService s2 = ctx.getBean(BookService.class);
    List<Book> books = s2.findByCommentAuthor("Jane Doe");

    System.out.println(books.size());
}

From source file:com.rytis.oot2.AppJavaConfig.java

public static void run(String[] args) throws Throwable {
    SpringApplication.run(AppJavaConfig.class, args);
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.scan("com.rytis.oot2");
    applicationContext.refresh();/*  ww w  . ja va  2  s  .  com*/

    Device device;
    device = applicationContext.getBean("device1", Device.class);
    device.Boot();
    device = applicationContext.getBean("device2", Device.class);
    device.Boot();
    device = applicationContext.getBean("device3", Device.class);
    device.Boot();
    device = applicationContext.getBean("device4", Device.class);
    device.Boot();
    device = applicationContext.getBean("device5", Device.class);
    device.Boot();
    device = applicationContext.getBean("device7", Device.class);
    device.Boot();
    device = applicationContext.getBean("device8", Device.class);
    device.Boot();

    ((AbstractApplicationContext) applicationContext).close();

}

From source file:springfox.documentation.spring.web.ObjectMapperConfigurerIntegrationTest.java

@Test
public void event_is_fired_when_default_rmh_is_loaded() {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            TestDefaultConfig.class);

    context.getBean("defaultRmh", RequestMappingHandlerAdapter.class);

    assertEquals(TestObjectMapperListener.firedCount, 1L);
}

From source file:springfox.documentation.spring.web.ObjectMapperConfigurerIntegrationTest.java

@Test
public void event_is_fired_when_rmh_with_multiple_message_converters_is_loaded() {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            TestMultipleConfig.class);

    context.getBean("multipleMCRmh", RequestMappingHandlerAdapter.class);

    assertEquals(TestObjectMapperListener.firedCount, 2L);
}