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:ro.pippo.demo.spring.SpringDemo2.java

public static void main(String[] args) {
    // create spring application context
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration2.class);
    Application application = (Application) applicationContext.getBean("application");

    Pippo pippo = new Pippo(application);
    pippo.start();//from  ww w .  ja v a2  s.co  m
}

From source file:com.khartec.waltz.jobs.RatedFlowHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    RatedDataFlowService ratedDataFlowService = ctx.getBean(RatedDataFlowService.class);

    int CTO_OFFICE = 40;
    int CTO_ADMIN = 400;
    int CEO_OFFICE = 10;
    int MARKET_RISK = 220;
    int RISK = 210;

    int orgUnitId = RISK;

    tree(ratedDataFlowService, orgUnitId);

}

From source file:com.khartec.waltz.jobs.PerformanceMetricPackHarness.java

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

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    PerformanceMetricPackDao dao = ctx.getBean(PerformanceMetricPackDao.class);

    System.out.println("Loading....");
    MetricPack pack = dao.getById(1L);/*from   w w w. jav  a2 s . c o  m*/

    System.out.println(pack);
}

From source file:com.khartec.waltz.jobs.SoftwareCatalogHarness.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    SoftwareCatalogService softwareCatalogService = ctx.getBean(SoftwareCatalogService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    EntityReference ref = ImmutableEntityReference.builder().kind(EntityKind.ORG_UNIT).id(20L).build();

    IdSelectionOptions options = ImmutableIdSelectionOptions.builder().entityReference(ref)
            .scope(HierarchyQueryScope.CHILDREN).build();

    SoftwareSummaryStatistics stats = softwareCatalogService.findStatisticsForAppIdSelector(options);
    System.out.println("stats:" + stats);
}

From source file:org.dimitrovchi.Demo.java

public static void main(String... args) throws Exception {
    final String confPkgName = DemoApplicationConfiguration.class.getPackage().getName();
    try (final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            confPkgName)) {/*from  w  w  w.  j a  v a2  s  . c om*/
        LOG.info("Context " + context + " started");
        context.start();
        Thread.sleep(60_000L);
    }
}

From source file:com.khartec.waltz.jobs.AuthSourceHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceCalculator authoritativeSourceCalculator = ctx
            .getBean(AuthoritativeSourceCalculator.class);

    long CTO_OFFICE = 40;
    long CTO_ADMIN = 400;
    long CEO_OFFICE = 10;
    long CIO_OFFICE = 20;
    long MARKET_RISK = 220;
    long CREDIT_RISK = 230;
    long OPERATIONS_IT = 200;
    long RISK = 210;

    long orgUnitId = CIO_OFFICE;

    authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId);

    long st = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        authoritativeSourceCalculator.calculateAuthSourcesForOrgUnitTree(orgUnitId);
    }/*from   w  w w .  j a  v a2  s.c  o m*/
    long end = System.currentTimeMillis();

    System.out.println("DUR " + (end - st));
    Map<Long, Map<String, Map<Long, AuthoritativeSource>>> rulesByOrgId = authoritativeSourceCalculator
            .calculateAuthSourcesForOrgUnitTree(orgUnitId);

    System.out.println("--CIO---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CIO_OFFICE));

    System.out.println("--RISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(RISK));

    System.out.println("--MARKETRISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(MARKET_RISK));

    System.out.println("--OPS---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(OPERATIONS_IT));

    System.out.println("--CREDIT RISK---");
    AuthoritativeSourceCalculator.prettyPrint(rulesByOrgId.get(CREDIT_RISK));

}

From source file:com.github.lanimall.ehcache2.AppNoCache.java

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

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceTester");
    tester.test();/*from ww  w . jav  a  2  s  .c o m*/

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}

From source file:com.curso.ejemplotareaplanificada.Principal.java

/**
 * @param args the command line arguments
 *///  w w  w .  j  a v a2 s.c  o m
public static void main(String[] args) {
    //solo estamos usando anotaciones
    //en esta clase no hay nada de los metodos planificados porque esos ya los llama spring solito
    //esta clase es para pegarnos con los servicios asincronos
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Configuracion.class);
    System.out.println("Contexto cargado");
    ServicioAsincrono sa = ctx.getBean(ServicioAsincrono.class);
    System.out.println("Hilo principal " + Thread.currentThread());

    //Este metodo devuelve void asi que el hilo arranca un nuevo hilo pero continua sin esperar ni ahora ni a un futuro
    sa.metodoUno();

    //Este metodo devuelve un futuro, y cuando llamemos a get espera 5 segundos a ver si termina el nuevo hilo
    //Si sobre pasa esos 5 segundos lanza una excepcion
    Future<Double> numero = sa.factorial(100);
    try {
        System.out.println("El factorial es desde un Future:" + numero.get(5L, TimeUnit.SECONDS));
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Este metodo devuelve un escuchable
    ListenableFuture<Double> valor = sa.factorialLf(100);
    //Al metodo escuchable le aadimos una clase anonima de tipo llamable con dos metodos, uno que se ejecutara cuando acabe con exito
    //y otro si no acaba correctamente
    valor.addCallback(new ListenableFutureCallback<Double>() {

        @Override
        public void onSuccess(Double result) {
            System.out.println("El resultado es desde un ListenableFuture: " + result);
        }

        @Override
        public void onFailure(Throwable ex) {
            LOG.log(Level.SEVERE, "Ha ocurrido un error:", ex);
        }
    });
}

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  w w  .  j av  a  2 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.github.lanimall.ehcache2.AppNativeEhcache.java

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

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceWithCacheAsideTester");
    tester.test();//w  ww.ja va2 s  . c  o  m

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}