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();
}
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 + "!");
}
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);
}
}
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);
}
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);
}
}
}
Aggregations