Example usage for org.springframework.context.support GenericXmlApplicationContext start

List of usage examples for org.springframework.context.support GenericXmlApplicationContext start

Introduction

In this page you can find the example usage for org.springframework.context.support GenericXmlApplicationContext start.

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.rcaspar.fitbitbat.App.java

/**
 * Program entry point.//  w ww  . ja v a2s.  c  o  m
 *
 * @param args CLI args
 */
public static void main(final String[] args) {
    log.debug("main() - args={}", Arrays.asList(args));
    final Args arguments = new Args();
    try {
        new JCommander(arguments, args);

        final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(
                "classpath:application-context.xml");
        applicationContext.registerShutdownHook();
        applicationContext.start();

        final Package appPackage = App.class.getPackage();
        log.info("=== {} v.{} started ===", appPackage.getImplementationTitle(),
                appPackage.getImplementationVersion());

        final FitBitBat fitBitBat = applicationContext.getBean(FitBitBat.class);
        if (fitBitBat.checkCredentials(arguments.getPin())) {
            fitBitBat.startAsync();
        } else {
            log.error("Bad pin: {}", arguments.getPin());
        }
    } catch (final OAuthException ex) {
        System.err.println(ex.getMessage());
        System.exit(1);
    } catch (final ParameterException ex) {
        new JCommander(arguments).usage();
        System.exit(-1);
    } catch (final Exception ex) {
        log.error("Cannot startup", ex);
        System.exit(-2);
    }
}

From source file:org.crsh.spring.SpringTestCase.java

public void testFoo() throws Exception {

    URL xml = SpringTestCase.class.getResource("spring.xml");
    Assert.assertNotNull(xml);// w  ww .j a va  2s. co  m

    //
    GenericXmlApplicationContext context = new GenericXmlApplicationContext(new UrlResource(xml));
    context.start();

    //
    SpringBootstrap bootstrap = context.getBean(SpringBootstrap.class);

    // Test a bit
    ShellFactory factory = bootstrap.getContext().getPlugin(ShellFactory.class);
    Shell shell = factory.create(null);
    assertNotNull(shell);
    ShellProcess process = shell.createProcess("foo_cmd");
    assertNotNull(process);
    BaseProcessContext pc = BaseProcessContext.create(process).execute();
    assertTrue(pc.getResponse() instanceof ShellResponse.Ok);
    String r = pc.getOutput();
    assertEquals("bar", r);
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.DBLoaderSpring.java

@Override
public void load() {

    GenericXmlApplicationContext ctx = null;
    try {// w  ww. ja v  a2s.com

        if (resource == null) {
            LOG.warn("Resource null for DBLoaderSpring");
        }

        ctx = new GenericXmlApplicationContext();
        ctx.load(resource);
        ctx.refresh();
        ctx.start();

        Collection<EntitlementEntity> entitlements = ctx.getBeansOfType(EntitlementEntity.class, true, true)
                .values();
        for (EntitlementEntity e : entitlements) {
            em.persist(e);
        }
        LOG.info(entitlements.size() + " EntitlementEntity added");

        Collection<RoleEntity> roles = ctx.getBeansOfType(RoleEntity.class, true, true).values();
        for (RoleEntity r : roles) {
            em.persist(r);
        }
        LOG.info(roles.size() + " RoleEntity added");

        Collection<ClaimEntity> claims = ctx.getBeansOfType(ClaimEntity.class, true, true).values();
        for (ClaimEntity c : claims) {
            em.persist(c);
        }
        LOG.info(claims.size() + " ClaimEntity added");

        Collection<TrustedIdpEntity> trustedIdps = ctx.getBeansOfType(TrustedIdpEntity.class).values();
        for (TrustedIdpEntity t : trustedIdps) {
            em.persist(t);
        }
        LOG.info(trustedIdps.size() + " TrustedIdpEntity added");

        Collection<ApplicationEntity> applications = ctx.getBeansOfType(ApplicationEntity.class).values();
        for (ApplicationEntity a : applications) {
            em.persist(a);
        }
        LOG.info(applications.size() + " ApplicationEntity added");

        Collection<IdpEntity> idps = ctx.getBeansOfType(IdpEntity.class).values();
        for (IdpEntity i : idps) {
            em.persist(i);
        }
        LOG.info(idps.size() + " IdpEntity added");

        Collection<ApplicationClaimEntity> applicationClaims = ctx.getBeansOfType(ApplicationClaimEntity.class)
                .values();
        for (ApplicationClaimEntity ac : applicationClaims) {
            em.persist(ac);
        }
        LOG.info(applicationClaims.size() + " ApplicationClaimEntity added");

        em.flush();
    } catch (Exception ex) {
        LOG.warn("Failed to initialize DB with data", ex);
    } finally {
        if (ctx != null) {
            ctx.close();
        }
    }
}