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(String... basePackages) 

Source Link

Document

Create a new AnnotationConfigApplicationContext, scanning for bean definitions in the given packages and automatically refreshing the context.

Usage

From source file:repository.StudioRepositoryTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    ctx = new AnnotationConfigApplicationContext(ConnectionConfig.class);
    eList = new ArrayList<Equipment>();

    eList.add(new Tablet.Builder().name("Lenovo").build());
    eList.add(new Smartboard.Builder().code("Smart A12330").build());
    eList.add(new DesktopPC.Builder().code("Mac-3435-34").build());

}

From source file:org.cellcore.code.exec.ExecConsolidate.java

@Override
protected void execute(CommandLine commandLine) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ContextConfig.class);
    final File crawlResultDir = new File(commandLine.getOptionValue("input"));
    boolean global = commandLine.hasOption("global");
    Collection<File> resultFiles = FileUtils.listFiles(crawlResultDir, new String[] { "data.json" }, true);
    CardPriceConsolidator conciliatePriceCrawlData = context.getBean(CardPriceConsolidator.class);
    Gson gson = GsonUtils.getSerializer();
    for (File crawlResultFile : resultFiles) {
        logger.info("processing file " + crawlResultFile.getAbsolutePath());
        try {//from  www .j  a  va2 s. co  m
            String fetched = FileUtils.readFileToString(crawlResultFile);
            try {
                Card[] cards = gson.fromJson(fetched, Card[].class);
                for (Card card : cards) {
                    if (card != null) {
                        if (global) {
                            conciliatePriceCrawlData.conciliateGlobal(card);
                        } else {
                            conciliatePriceCrawlData.conciliate(card);
                        }
                    }
                }

            } catch (Throwable t) {
                logger.error("ERROR PROCESSING FILE: " + crawlResultFile.getAbsolutePath(), t);
            }
        } catch (Throwable t) {
            logger.error("ERROR READING FILE: " + crawlResultFile.getAbsolutePath(), t);
        }
    }

    if (global) {
        for (Map.Entry<String, Card> entry : conciliatePriceCrawlData.getGlobalCards().entrySet()) {
            conciliatePriceCrawlData.conciliate(entry.getValue());
        }
    }
}

From source file:org.drizzly.MySQLConnectionTest.java

@Test
public void testGetAllEmployees() {
    ApplicationContext application = new AnnotationConfigApplicationContext(EmployeeManager.class);
    EmployeeManager emp = application.getBean(EmployeeManager.class);
    Long empId = new Long(1);
    EmployeeDAO dao = new EmployeeDAO();
    Assert.notEmpty(dao.findAllEmployees());

}

From source file:com.ngcamango.rehabcetreweb.test.repository.AssessmentRepositoryTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    ctx = new AnnotationConfigApplicationContext(ConnectionConfig.class);
    progress = new Progress.Builder("Good").build();
    timeElapsed = new Time.Builder(01).build();
}

From source file:nats.client.spring.JavaConfigAnnotationConfigTest.java

@Test
public void subscribeAnnotationNamedNatsBean() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            NamedNatsAnnotationConfig.class);
    try {//from   w w  w  .  j  a  v  a 2 s .  c  om
        final Nats nats = context.getBean(NATS_BEAN, Nats.class);
        final Nats wrongNats = context.getBean(WRONG_NATS_BEAN, Nats.class);
        wrongNats.publish("test", "Should not get processed");
        testNatsConfig(context, nats);
    } finally {
        context.close();
    }
}

From source file:de.olivergierke.samples.datanucleus.SpringTestCase.java

@Test
public void bootstrapJpa() {

    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    EntityManagerFactory factory = context.getBean(EntityManagerFactory.class);

    SimpleTestCase.executeTestWith(factory);

    context.close();/*www  .j a v  a 2 s  .com*/
}

From source file:org.seasar.doma.boot.autoconfigure.TryLookupEntityListenerProviderTest.java

@Test(expected = IllegalStateException.class)
public void testManaged_notUnique() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(FooConfig.class);
    TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider();
    provider.setApplicationContext(context);
    provider.get(FooListener.class, FooListener::new);
}

From source file:repository.PhotographerRepositoryTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    ctx = new AnnotationConfigApplicationContext(ConnectionConfig.class);
    c = new ArrayList<Camera>();
    cam = new Camera.Builder().name("Canon D900").build();
    pc = new DesktopPC.Builder().code("Acer 12-W3").build();
    tablet = new Tablet.Builder().code("Lenovo 11-E2").build();
    c.add(cam);//from   ww  w. j a  va  2  s.  co  m
}

From source file:org.cellcore.code.exec.ExecPullFromGatherer.java

@Override
protected void execute(CommandLine commandLine) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ContextConfig.class);
    FetchGathererData fgd = context.getBean(FetchGathererData.class);
    GeneralDao dao = context.getBean(GeneralDao.class);
    Gson gson = GsonUtils.getSerializer();
    String configString = null;//from  ww  w.j  a v a 2 s  .  c  om
    try {
        configString = FileUtils.readFileToString(new File(commandLine.getOptionValue("input")));
        CrawlConfiguration config = gson.fromJson(configString, CrawlConfiguration.class);
        GathererEditionLocationCrawler crawler = new GathererEditionLocationCrawler("");

        for (Map.Entry<String, String> cardSet : config.getCardSets().entrySet()) {
            List<String> cardIds = crawler.crawlPage(cardSet.getValue());
            logger.info("PROCESSING: " + cardSet + " " + cardIds.size() + " cards");
            fgd.extract(cardSet.getKey(), cardIds);
        }
    } catch (IOException e) {
        logger.error("", e);
    }

}

From source file:org.apache.camel.component.gridfs.AbstractMongoDbTest.java

@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class);
    CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
    ctx.addComponent("properties", pc);
    return ctx;/*  w w  w.  j a  va  2 s . co m*/
}