Search in sources :

Example 51 with ApplicationContext

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

the class AbstractGrailsPluginManager method doDynamicMethods.

public void doDynamicMethods() {
    checkInitialised();
    Class<?>[] allClasses = application.getAllClasses();
    if (allClasses != null) {
        for (Class<?> c : allClasses) {
            ExpandoMetaClass emc = new ExpandoMetaClass(c, true, true);
            emc.initialize();
        }
        ApplicationContext ctx = applicationContext;
        for (GrailsPlugin plugin : pluginList) {
            if (!plugin.isEnabled(ctx.getEnvironment().getActiveProfiles()))
                continue;
            plugin.doWithDynamicMethods(ctx);
        }
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GrailsPlugin(grails.plugins.GrailsPlugin) ExpandoMetaClass(groovy.lang.ExpandoMetaClass) ExpandoMetaClass(groovy.lang.ExpandoMetaClass)

Example 52 with ApplicationContext

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

the class DefaultRuntimeSpringConfiguration method registerBeansWithConfig.

public void registerBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig) {
    if (targetSpringConfig == null) {
        return;
    }
    ApplicationContext ctx = targetSpringConfig.getUnrefreshedApplicationContext();
    if (ctx instanceof BeanDefinitionRegistry) {
        final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx;
        registerUnrefreshedBeansWithRegistry(registry);
        registerBeansWithRegistry(registry);
    }
    for (Map.Entry<String, BeanConfiguration> beanEntry : beanConfigs.entrySet()) {
        targetSpringConfig.addBeanConfiguration(beanEntry.getKey(), beanEntry.getValue());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 53 with ApplicationContext

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

the class RoutesCollector method onApplicationEvent.

// Overridden
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ApplicationContext applicationContext = event.getApplicationContext();
    // only listen to context refresh of "my" applicationContext
    if (this.applicationContext.equals(applicationContext)) {
        CamelContext camelContext = event.getApplicationContext().getBean(CamelContext.class);
        // only add and start Camel if its stopped (initial state)
        if (camelContext.getStatus().isStopped()) {
            LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
            for (RoutesBuilder routesBuilder : configuration.routes()) {
                // filter out abstract classes
                boolean abs = Modifier.isAbstract(routesBuilder.getClass().getModifiers());
                if (!abs) {
                    try {
                        LOG.debug("Injecting following route into the CamelContext: {}", routesBuilder);
                        camelContext.addRoutes(routesBuilder);
                    } catch (Exception e) {
                        throw new CamelSpringJavaconfigInitializationException(e);
                    }
                }
            }
            try {
                boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
                if (skip) {
                    LOG.info("Skipping starting CamelContext(s) as system property skipStartingCamelContext is set to be true.");
                } else {
                    // start camel
                    camelContext.start();
                }
            } catch (Exception e) {
                throw new CamelSpringJavaconfigInitializationException(e);
            }
        }
    } else {
        LOG.debug("Ignore ContextRefreshedEvent: {}", event);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ApplicationContext(org.springframework.context.ApplicationContext) RoutesBuilder(org.apache.camel.RoutesBuilder)

Example 54 with ApplicationContext

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

the class MainTest method createCamelContext.

private CamelContext createCamelContext(String[] options) throws Exception {
    Main main = new Main();
    main.parseArguments(options);
    ApplicationContext applicationContext = main.createDefaultApplicationContext();
    CamelContext context = SpringCamelContext.springCamelContext(applicationContext);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ApplicationContext(org.springframework.context.ApplicationContext)

Example 55 with ApplicationContext

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

the class PlainSpringCustomPostProcessorOnRouteBuilderTest method testShouldProcessAnnotatedFields.

public void testShouldProcessAnnotatedFields() {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/org/apache/camel/spring/postprocessor/plainSpringCustomPostProcessorOnRouteBuilderTest.xml");
    assertNotNull("Context not created", context);
    assertNotNull("Post processor not registered", context.getBeansOfType(MagicAnnotationPostProcessor.class));
    TestPojo pojo = context.getBean("testPojo", TestPojo.class);
    assertNotNull("Test pojo not registered", pojo);
    assertEquals("Processor has not changed field value", "Changed Value", pojo.getTestValue());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13