Search in sources :

Example 1 with BeanBuilder

use of grails.spring.BeanBuilder in project grails-core by grails.

the class DefaultGrailsPlugin method doWithRuntimeConfiguration.

public void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
    Binding b = new Binding();
    b.setVariable("application", grailsApplication);
    b.setVariable(GrailsApplication.APPLICATION_ID, grailsApplication);
    b.setVariable("manager", getManager());
    b.setVariable("plugin", this);
    b.setVariable("parentCtx", getParentCtx());
    b.setVariable("resolver", getResolver());
    if (plugin instanceof Plugin) {
        Closure c = ((Plugin) plugin).doWithSpring();
        if (c != null) {
            BeanBuilder bb = new BeanBuilder(getParentCtx(), springConfig, grailsApplication.getClassLoader());
            bb.setBinding(b);
            bb.invokeMethod("beans", new Object[] { c });
        }
    } else {
        if (!pluginBean.isReadableProperty(DO_WITH_SPRING)) {
            return;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Plugin " + this + " is participating in Spring configuration...");
        }
        Closure c = (Closure) plugin.getProperty(DO_WITH_SPRING);
        BeanBuilder bb = new BeanBuilder(getParentCtx(), springConfig, grailsApplication.getClassLoader());
        bb.setBinding(b);
        c.setDelegate(bb);
        bb.invokeMethod("beans", new Object[] { c });
    }
}
Also used : BeanBuilder(grails.spring.BeanBuilder) GrailsPlugin(grails.plugins.GrailsPlugin) Plugin(grails.plugins.Plugin)

Example 2 with BeanBuilder

use of grails.spring.BeanBuilder in project grails-core by grails.

the class GrailsWebApplicationContext method prepareBeanFactory.

@Override
protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    if (configLocations.length > 0) {
        for (String configLocation : configLocations) {
            BeanBuilder beanBuilder = new BeanBuilder(getParent(), getClassLoader());
            final ServletContextResource resource = new ServletContextResource(getServletContext(), configLocation);
            beanBuilder.loadBeans(resource);
            beanBuilder.registerBeans(this);
        }
    }
    super.prepareBeanFactory(beanFactory);
}
Also used : BeanBuilder(grails.spring.BeanBuilder) ServletContextResource(org.springframework.web.context.support.ServletContextResource)

Example 3 with BeanBuilder

use of grails.spring.BeanBuilder in project grails-core by grails.

the class RuntimeSpringConfigUtilities method reloadSpringResourcesConfig.

public static BeanBuilder reloadSpringResourcesConfig(RuntimeSpringConfiguration config, GrailsApplication application, Class<?> groovySpringResourcesClass) throws InstantiationException, IllegalAccessException {
    springGroovyResourcesBeanBuilder = new BeanBuilder(null, config, Thread.currentThread().getContextClassLoader());
    springGroovyResourcesBeanBuilder.setBinding(new Binding(CollectionUtils.newMap("application", application, "grailsApplication", // GRAILS-7550
    application)));
    Script script = (Script) groovySpringResourcesClass.newInstance();
    script.run();
    Object beans = script.getProperty("beans");
    springGroovyResourcesBeanBuilder.beans((Closure<?>) beans);
    return springGroovyResourcesBeanBuilder;
}
Also used : BeanBuilder(grails.spring.BeanBuilder) Binding(groovy.lang.Binding) Script(groovy.lang.Script)

Example 4 with BeanBuilder

use of grails.spring.BeanBuilder in project grails-core by grails.

the class DefaultGrailsPlugin method beans.

public BeanBuilder beans(Closure closure) {
    BeanBuilder bb = new BeanBuilder(getParentCtx(), new GroovyClassLoader(grailsApplication.getClassLoader()));
    bb.invokeMethod("beans", new Object[] { closure });
    return bb;
}
Also used : BeanBuilder(grails.spring.BeanBuilder)

Aggregations

BeanBuilder (grails.spring.BeanBuilder)4 GrailsPlugin (grails.plugins.GrailsPlugin)1 Plugin (grails.plugins.Plugin)1 Binding (groovy.lang.Binding)1 Script (groovy.lang.Script)1 ServletContextResource (org.springframework.web.context.support.ServletContextResource)1