Search in sources :

Example 1 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project zeppelin by apache.

the class LensBootstrap method getLensJLineShellComponent.

public LensJLineShellComponent getLensJLineShellComponent() {
    GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition();
    rbd.setBeanClass(LensJLineShellComponent.class);
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
    bf.registerBeanDefinition(LensJLineShellComponent.class.getSimpleName(), rbd);
    return ctx.getBean(LensJLineShellComponent.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition)

Example 2 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project cucumber-jvm by cucumber.

the class CucumberTestContextManager method createFallbackContext.

@SuppressWarnings("resource")
private ConfigurableListableBeanFactory createFallbackContext() {
    ConfigurableApplicationContext applicationContext;
    if (getClass().getClassLoader().getResource("cucumber.xml") != null) {
        applicationContext = new ClassPathXmlApplicationContext("cucumber.xml");
    } else {
        applicationContext = new GenericApplicationContext();
    }
    applicationContext.registerShutdownHook();
    ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    beanFactory.registerScope(GlueCodeScope.NAME, new GlueCodeScope());
    for (Class<?> stepClass : stepClasses) {
        registerStepClassBeanDefinition(beanFactory, stepClass);
    }
    return beanFactory;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 3 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomain.

@Test
public void testRegistrationWithDifferentDomain() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class, null, new MutablePropertyValues(Collections.singletonMap("domain", "test-domain"))));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("test-domain", "endpoint1", false, this.context))).isNotNull();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 4 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testSkipRegistrationOfDisabledEndpoint.

@Test
public void testSkipRegistrationOfDisabledEndpoint() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.add("enabled", Boolean.FALSE);
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class, null, mpv));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().isRegistered(getObjectName("endpoint1", this.context))).isFalse();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 5 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method registerLoggersEndpoint.

private MBeanExporter registerLoggersEndpoint() {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    RootBeanDefinition bd = new RootBeanDefinition(LoggersEndpoint.class);
    ConstructorArgumentValues values = new ConstructorArgumentValues();
    values.addIndexedArgumentValue(0, new LogbackLoggingSystem(getClass().getClassLoader()));
    bd.setConstructorArgumentValues(values);
    this.context.registerBeanDefinition("loggersEndpoint", bd);
    this.context.refresh();
    return this.context.getBean(EndpointMBeanExporter.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) LogbackLoggingSystem(org.springframework.boot.logging.logback.LogbackLoggingSystem) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)378 Test (org.junit.jupiter.api.Test)193 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)106 Test (org.junit.Test)74 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)72 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 ClassPathResource (org.springframework.core.io.ClassPathResource)36 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 QueueChannel (org.springframework.integration.channel.QueueChannel)16 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)15 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)15 GenericMessage (org.springframework.messaging.support.GenericMessage)14 Properties (java.util.Properties)13 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)13 File (java.io.File)12 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)12 Message (org.springframework.messaging.Message)12 InputStreamResource (org.springframework.core.io.InputStreamResource)11 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10