Example usage for org.springframework.context ConfigurableApplicationContext refresh

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

Introduction

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

Prototype

void refresh() throws BeansException, IllegalStateException;

Source Link

Document

Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.

Usage

From source file:org.wso2.msf4j.spring.MSF4JSpringApplication.java

public static ConfigurableApplicationContext run(Class sources, String... args) {
    MSF4JSpringApplication application = new MSF4JSpringApplication(sources);
    ConfigurableApplicationContext context = application.run(false, args);
    application.applyInitializers(context);
    context.refresh();
    return context;
}

From source file:org.springsource.investigation.ReproTests.java

@SuppressWarnings("unchecked")
@Test/* w w  w.  j  a  v  a2  s .c om*/
public void repro() {
    ConfigurableApplicationContext parent = new GenericApplicationContext();
    parent.refresh();

    AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
    child.setParent(parent);
    child.refresh();

    ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
    assertThat("UNKNOWN ENV", env,
            anyOf(sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment())));
    assertThat("EXPECTED CHILD CTX ENV", env, sameInstance(child.getEnvironment()));
}

From source file:com.rllc.batch.webcast.DynamicFtpChannelResolver.java

private synchronized MessageChannel createNewFileChannel(String fileName) {
    MessageChannel channel = this.channels.get(fileName);
    if (channel == null) {
        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
                new String[] { "dynamic-ftp-outbound-adapter-context.xml" }, false);
        this.setEnvironmentForFile(ctx, fileName);
        ctx.refresh();
        channel = ctx.getBean("toFtpChannel", MessageChannel.class);
        this.channels.put(fileName, channel);
        // Will works as the same reference is presented always
        this.contexts.put(channel, ctx);
    }//from ww w. j  a  va 2 s  . co m
    return channel;
}

From source file:com.github.exper0.efilecopier.ftp.DynamicFtpChannelResolver.java

private synchronized MessageChannel createNewCustomerChannel(String customer) {
    MessageChannel channel = this.channels.get(customer);
    if (channel == null) {
        ReportSettings settings = new FtpReportSettings();
        settings.setPassword("demo");
        settings.setUser("demo");
        settings.setHost("localhost");
        settings.setPort(4444);/*w w  w  .  j a  va  2 s.c o  m*/
        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
                new String[] { "/META-INF/spring/integration/dynamic-ftp-outbound-adapter-context.xml" }, false,
                getContext(settings));
        this.setEnvironmentForCustomer(ctx, customer);
        ctx.refresh();
        channel = ctx.getBean("toFtpChannel", MessageChannel.class);
        this.channels.put(customer, channel);
        //Will works as the same reference is presented always
        this.contexts.put(channel, ctx);
    }
    return channel;
}

From source file:org.openwms.core.startup.ApplicationInitializer.java

/**
 * {@inheritDoc}//from  w ww.  j a  va2 s  .  co  m
 * 
 * Depending on the underlying platform, different Spring profiles are
 * included.
 */
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    String activeProfile = System.getProperty("spring.profiles.active");
    if ("OSGI".equalsIgnoreCase(activeProfile)) {
        LOGGER.info("Running in OSGI environment");
    } else if ("noOSGI".equalsIgnoreCase(activeProfile)) {
        LOGGER.info("Running in a non-OSGI environment");
    } else {
        applicationContext.getEnvironment().setActiveProfiles("noOSGI");
        applicationContext.refresh();
        LOGGER.info("Switched to a non-OSGI environment");
    }
}

From source file:org.wso2.msf4j.spring.MSF4JSpringApplication.java

protected ConfigurableApplicationContext run(boolean doRefresh, String... args) {
    ConfigurableApplicationContext context = createApplicationContext();
    if (configurationClass != null) {
        registerIfAnnotationConfigApplicationContext(context);
    } else {//from  w ww.ja  v  a 2s.  c o m
        scanIfAnnotationConfigApplicationContext(context);
    }

    context.getEnvironment().getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));

    if (doRefresh) {
        context.refresh();
    }
    return context;
}

From source file:com.ms.commons.test.BaseTestCase.java

/**
 * Service???/*from  w w w.java 2s  .  co m*/
 * 
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
protected void initMoke() throws InstantiationException, IllegalAccessException {
    // Mock once on startup
    if (isMockOn()) {

        if (log.isDebugEnabled()) {
            log.debug("================>initMock!");
        }
        ConfigurableApplicationContext context = (ConfigurableApplicationContext) CommonServiceLocator
                .getApplicationContext();
        context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

            public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
                    throws BeansException {
                beanFactory.addBeanPostProcessor(new MockBeanPostProcessor());
            }
        });
        context.refresh();
    }
}

From source file:de.micromata.genome.gwiki.model.config.GWikiAbstractSpringContextBootstrapConfigLoader.java

@Override
public GWikiDAOContext loadConfig(ServletConfig config) {
    if (config != null && StringUtils.isBlank(fileName) == true) {
        fileName = config//from w w  w  . j  av  a 2 s .c o  m
                .getInitParameter("de.micromata.genome.gwiki.model.config.GWikiBootstrapConfigLoader.fileName");
        supportsJndi = StringUtils.equals(config.getInitParameter("de.micromata.genome.gwiki.supportsJndi"),
                "true");
    }
    ConfigurableApplicationContext actx = createApplicationContext(config, getApplicationContextName());
    actx.addBeanFactoryPostProcessor(new GWikiDAOContextPropertyPlaceholderConfigurer(config, supportsJndi));
    actx.refresh();
    beanFactory = actx;
    GWikiDAOContext daoContext = (GWikiDAOContext) actx.getBean("GWikiBootstrapConfig");

    daoContext.setBeanFactory(beanFactory);
    return daoContext;
}

From source file:org.sakaiproject.component.cover.TestComponentManagerContainer.java

/**
 * create a component manager based on a list of component.xml
 * @param configPaths a ';' seperated list of xml bean config files
 * @throws IOException//  w  w w  . j  a  va  2 s .  c o m
 */
public TestComponentManagerContainer(String configPaths, Properties props) throws IOException {
    // we assume that all the jars are in the same classloader, so this will
    // not check for
    // incorrect bindings and will not fully replicate the tomcat
    // experience, but is an easier environment
    // to work within for kernel testing.
    // For a more complex structure we could use the kernel poms in the repo
    // to generate the dep list.
    if (ComponentManager.m_componentManager != null) {
        log.info("Closing existing Component Manager ");
        /*         
         try {
           ComponentManager.m_componentManager.close();
        } catch ( Throwable t ) {
           log.warn("Close Failed with message, safe to ignore "+t.getMessage());
        }
        */
        log.info("Closing Complete ");
        ComponentManager.m_componentManager = null;
    }

    log.info("Starting Component Manager with [" + configPaths + "]");
    ComponentManager.setLateRefresh(true);

    componentManager = (SpringCompMgr) ComponentManager.getInstance();
    ConfigurableApplicationContext ac = componentManager.getApplicationContext();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    // Supply any additional configuration.
    if (props != null) {
        PropertyOverrideConfigurer beanFactoryPostProcessor = new PropertyOverrideConfigurer();
        beanFactoryPostProcessor.setBeanNameSeparator("@");
        beanFactoryPostProcessor.setProperties(props);
        ac.addBeanFactoryPostProcessor(beanFactoryPostProcessor);
    }

    // we could take the kernel bootstrap from from the classpath in future
    // rather than from
    // the filesystem

    List<Resource> config = new ArrayList<Resource>();
    String[] configPath = configPaths.split(";");
    for (String p : configPath) {
        File xml = new File(p);
        config.add(new FileSystemResource(xml.getCanonicalPath()));
    }
    loadComponent(ac, config, classLoader);

    ac.refresh();

    // SAK-20908 - band-aid for TLM sync issues causing tests to fail
    // This sleep shouldn't be needed but it seems these tests are starting before ThreadLocalManager has finished its startup.
    try {
        Thread.sleep(500); // 1/2 second
        log.debug("Finished starting the component manager");
    } catch (InterruptedException e) {
        log.error("Component manager startup interrupted...");
    }
}

From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java

protected DirectChannel createBindableChannel(String channelName, BindingProperties bindingProperties)
        throws Exception {
    BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
    bindingServiceProperties.getBindings().put(channelName, bindingProperties);
    ConfigurableApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.refresh();
    bindingServiceProperties.setApplicationContext(applicationContext);
    bindingServiceProperties.setConversionService(new DefaultConversionService());
    bindingServiceProperties.afterPropertiesSet();
    DirectChannel channel = new DirectChannel();
    channel.setBeanName(channelName);/*  w  w w  .j  a v  a  2 s .co m*/
    MessageConverterConfigurer messageConverterConfigurer = new MessageConverterConfigurer(
            bindingServiceProperties, new CompositeMessageConverterFactory(null, null));
    messageConverterConfigurer.setBeanFactory(applicationContext.getBeanFactory());
    messageConverterConfigurer.afterPropertiesSet();
    messageConverterConfigurer.configureOutputChannel(channel, channelName);
    return channel;
}