Search in sources :

Example 86 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project dubbo by alibaba.

the class Spring3CompatibilityTest method main.

public static void main(String[] args) {
    ConfigurableApplicationContext provider = startupProvider();
    ConfigurableApplicationContext consumer = startConsumer();
    ConsumerConfiguration consumerConfiguration = consumer.getBean(ConsumerConfiguration.class);
    DemoService demoService = consumerConfiguration.getDemoService();
    String value = demoService.sayHello("Mercy");
    Assert.isTrue("DefaultDemoService - sayHell() : Mercy".equals(value), "Test is failed!");
    System.out.println(value);
    provider.close();
    consumer.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConsumerConfiguration(com.alibaba.dubbo.test.consumer.ConsumerConfiguration) DemoService(com.alibaba.dubbo.demo.DemoService)

Example 87 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project grails-core by grails.

the class DefaultGrailsApplication method addArtefact.

protected GrailsClass addArtefact(String artefactType, Class<?> artefactClass, boolean overrideable) {
    ArtefactHandler handler = artefactHandlersByName.get(artefactType);
    if (handler != null && handler.isArtefact(artefactClass)) {
        GrailsClass artefactGrailsClass;
        if (handler instanceof DomainClassArtefactHandler) {
            artefactGrailsClass = ((DomainClassArtefactHandler) handler).newArtefactClass(artefactClass, proxyMappingContext);
        } else {
            artefactGrailsClass = handler.newArtefactClass(artefactClass);
        }
        artefactGrailsClass.setGrailsApplication(this);
        // Store the GrailsClass in cache
        DefaultArtefactInfo info = getArtefactInfo(artefactType, true);
        if (overrideable) {
            info.addOverridableGrailsClass(artefactGrailsClass);
        } else {
            info.addGrailsClass(artefactGrailsClass);
        }
        info.updateComplete();
        addToLoaded(artefactClass);
        if (isInitialised()) {
            initializeArtefacts(artefactType);
            ApplicationContext context = getMainContext();
            if (context instanceof ConfigurableApplicationContext && contextInitialized && ((ConfigurableApplicationContext) context).isActive()) {
                context.publishEvent(new ArtefactAdditionEvent(artefactGrailsClass));
            }
        }
        return artefactGrailsClass;
    }
    throw new GrailsConfigurationException("Cannot add " + artefactType + " class [" + artefactClass + "]. It is not a " + artefactType + "!");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactAdditionEvent(grails.core.events.ArtefactAdditionEvent)

Example 88 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project camel by apache.

the class CamelSpringDelegatingTestContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    Class<?> testClass = getTestClass();
    if (logger.isDebugEnabled()) {
        logger.debug("Loading ApplicationContext for merged context configuration [{}].", mergedConfig);
    }
    // Pre CamelContext(s) instantiation setup
    CamelAnnotationsHandler.handleDisableJmx(null, testClass);
    try {
        SpringCamelContext.setNoStart(true);
        System.setProperty("skipStartingCamelContext", "true");
        ConfigurableApplicationContext context = (ConfigurableApplicationContext) super.loadContext(mergedConfig);
        SpringCamelContext.setNoStart(false);
        System.clearProperty("skipStartingCamelContext");
        return loadContext(context, testClass);
    } finally {
        cleanup(testClass);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext)

Example 89 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project camel by apache.

the class CamelSpringBootExecutionListener method beforeTestMethod.

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    LOG.info("@RunWith(CamelSpringBootJUnit4ClassRunner.class) before: {}.{}", testContext.getTestClass(), testContext.getTestMethod().getName());
    Class<?> testClass = testContext.getTestClass();
    ConfigurableApplicationContext context = (ConfigurableApplicationContext) testContext.getApplicationContext();
    // mark Camel to be startable again and start Camel
    System.clearProperty("skipStartingCamelContext");
    LOG.info("Initialized CamelSpringBootJUnit4ClassRunner now ready to start CamelContext");
    CamelAnnotationsHandler.handleCamelContextStartup(context, testClass);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext)

Example 90 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project camel by apache.

the class SpringCamelContext method setApplicationContext.

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    ClassLoader cl;
    // set the application context classloader
    if (applicationContext != null && applicationContext.getClassLoader() != null) {
        cl = applicationContext.getClassLoader();
    } else {
        LOG.warn("Cannot find the class loader from application context, using the thread context class loader instead");
        cl = Thread.currentThread().getContextClassLoader();
    }
    LOG.debug("Set the application context classloader to: {}", cl);
    this.setApplicationContextClassLoader(cl);
    if (applicationContext instanceof ConfigurableApplicationContext) {
        // only add if not already added
        if (hasComponent("spring-event") == null) {
            eventComponent = new EventComponent(applicationContext);
            addComponent("spring-event", eventComponent);
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) EventComponent(org.apache.camel.component.event.EventComponent)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)177 Test (org.junit.Test)110 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)17 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 DataSource (javax.sql.DataSource)8 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)6 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4