Example usage for org.springframework.context ConfigurableApplicationContext getBean

List of usage examples for org.springframework.context ConfigurableApplicationContext getBean

Introduction

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

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:com.provenance.cloudprovenance.eventhandler.service.test.TraceabilityConsumerTest.java

@Before
public void init() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "beans.xml" });

    tProducer = (EventProducer<TraceabilityDocument>) ctx.getBean("eventProducer");
}

From source file:org.solmix.runtime.support.spring.SpringContainerFactory.java

/**
 * @param cac/*from   w  ww. jav a  2  s. co  m*/
 * @return
 */
private Container completeCreating(ConfigurableApplicationContext spring) {
    Container system = (Container) spring.getBean(Container.DEFAULT_CONTAINER_ID);
    system.setExtension(spring, ApplicationContext.class);
    possiblySetDefaultContainer(system);
    initializeContainer(system);
    if (system instanceof SpringContainer && defaultContextNotExists()) {
        ((SpringContainer) system).setCloseContext(true);
    }
    return system;
}

From source file:net.tirasa.blog.springquartz.SpringBeanJobFactory.java

/**
 * An implementation of SpringBeanJobFactory that retrieves the bean from
 * the Spring context so that autowiring and transactions work
 *
 * This method is overriden.//w  w w.  j  a v a2 s  .  c om
 * @see org.springframework.scheduling.quartz.SpringBeanJobFactory#createJobInstance(org.quartz.spi.TriggerFiredBundle)
 */
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {

    final ConfigurableApplicationContext ctx = ((ConfigurableApplicationContext) schedulerContext
            .get("applicationContext"));
    final Object job = ctx.getBean(bundle.getJobDetail().getName());
    final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(job);
    if (isEligibleForPropertyPopulation(wrapper.getWrappedInstance())) {
        final MutablePropertyValues pvs = new MutablePropertyValues();
        if (this.schedulerContext != null) {
            pvs.addPropertyValues(this.schedulerContext);
        }
        pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap());
        pvs.addPropertyValues(bundle.getTrigger().getJobDataMap());
        if (this.ignoredUnknownProperties == null) {
            wrapper.setPropertyValues(pvs, true);
        } else {
            for (String propName : this.ignoredUnknownProperties) {
                if (pvs.contains(propName) && !wrapper.isWritableProperty(propName)) {

                    pvs.removePropertyValue(propName);
                }
            }
            wrapper.setPropertyValues(pvs);
        }
    }
    return job;
}

From source file:samples.websocket.echo.SampleWebSocketsApplicationTests.java

@Test
public void runAndWait() throws Exception {
    ConfigurableApplicationContext context = SpringApplication.run(ClientConfiguration.class,
            "--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    context.close();//from   www  .j a  v a2 s.  c o  m
    assertEquals(0, count);
}

From source file:org.jas.Launcher.java

public Launcher(ConfigurableApplicationContext applicationContext) {
    DefaultEngine defaultEngine = applicationContext.getBean(DefaultEngine.class);
    defaultEngine.start();/*from   w  w  w  .ja v a 2 s. com*/
}

From source file:org.huahinframework.manager.Runner.java

/**
 * @param war/*  w  w  w .  ja  v a2 s .  co  m*/
 * @param port
 */
public void start(String war, int port) {
    log.info("huahin-manager start");

    ConfigurableApplicationContext applicationContext = null;
    try {
        applicationContext = new ClassPathXmlApplicationContext("huahinManagerProperties.xml");
        Properties properties = (Properties) applicationContext.getBean("properties");

        Thread queueManager = new QueueManager(properties);
        queueManager.start();

        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setPort(port);

        Server server = new Server();
        server.setConnectors(new Connector[] { connector });

        WebAppContext web = new WebAppContext();
        web.setContextPath("/");
        web.setWar(war);

        server.addHandler(web);
        server.start();
        server.join();
        queueManager.join();
    } catch (Exception e) {
        log.error("huahin-manager aborted", e);
        System.exit(-1);
    }

    log.info("huahin-manager end");
}

From source file:com.intelligrated.ftp.services.FtpOutboundGatewayService.java

public void testLsGetRm() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml");

    final ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);

    // execute the flow (ls, get, rm, aggregate results)
    List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("/");

    //Check everything went as expected, and clean up
    assertEquals("Was expecting the collection 'rmResults' to contain 2 elements.", 2, rmResults.size());

    for (Boolean result : rmResults) {
        assertTrue(result);//from  w w  w.  j av a  2 s  .c o m
    }

    //assertTrue("Expected FTP remote directory to be empty",  new File(TestSuite.FTP_ROOT_DIR).delete());

    ctx.close();
}

From source file:com.acme.oms.ui.RunnerVaadinApplication.java

@Override
public void init() {

    @SuppressWarnings("resource")
    ConfigurableApplicationContext appCtx = new ClassPathXmlApplicationContext(
            "META-INF/spring/application-context.xml");
    appCtx.registerShutdownHook();//from  ww w  . j  a va2s  .  c o m
    queryRepository = appCtx.getBean(JpaOrderQueryRepository.class);
    commandBus = appCtx.getBean(CommandBus.class);

    window = new Window("Order Management System");

    orderForm = new OrderForm(commandBus);
    orderList = new OrderList(new OrderContainer(queryRepository));
    orderListView = new OrderListView(orderList, orderForm);

    window.addComponent(orderListView);
    window.getContent().setSizeFull();
    setMainWindow(window);
}

From source file:com.aeg.ims.ftp.SftpOutboundGatewaySample.java

@Test
public void testLsGetRm() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
            "classpath:/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml");
    ToSftpFlowGateway toFtpFlow = ctx.getBean(ToSftpFlowGateway.class);
    RemoteFileTemplate<LsEntry> template = null;
    String file1 = "1.ftptest";
    String file2 = "2.ftptest";
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));

    try {//w ww  .j a v  a  2 s .  co  m
        // remove the previous output files if necessary
        new File(tmpDir, file1).delete();
        new File(tmpDir, file2).delete();

        @SuppressWarnings("unchecked")
        SessionFactory<LsEntry> sessionFactory = ctx.getBean(CachingSessionFactory.class);
        template = new RemoteFileTemplate<LsEntry>(sessionFactory);
        SftpTestUtils.createTestFiles(template, file1, file2);

        // execute the flow (ls, get, rm, aggregate results)
        List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("si.sftp.sample");

        //Check everything went as expected, and clean up
        assertEquals(2, rmResults.size());
        for (Boolean result : rmResults) {
            assertTrue(result);
        }

    } finally {
        SftpTestUtils.cleanUp(template, file1, file2);
        ctx.close();
        assertTrue("Could note delete retrieved file", new File(tmpDir, file1).delete());
        assertTrue("Could note delete retrieved file", new File(tmpDir, file2).delete());
    }
}