Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerResolvableDependency

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerResolvableDependency

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerResolvableDependency.

Prototype

void registerResolvableDependency(Class<?> dependencyType, @Nullable Object autowiredValue);

Source Link

Document

Register a special dependency type with corresponding autowired value.

Usage

From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java

@Bean
public static CustomScopeConfigurer webSocketScopeConfigurer(ConfigurableListableBeanFactory beanFactory) {

    beanFactory.registerResolvableDependency(WebSocketSession.class,
            new WampSessionScope.WebSocketSessionObjectFactory());
    beanFactory.registerResolvableDependency(WampSession.class,
            new WampSessionScope.WampSessionObjectFactory());

    CustomScopeConfigurer configurer = new CustomScopeConfigurer();
    configurer.addScope("wampsession", new WampSessionScope());
    return configurer;
}

From source file:runkoserver.integration.SeleniumTestExecutionListener.java

@Override
public void prepareTestInstance(TestContext testContext) throws Exception {
    if (webDriver != null) {
        return;/*  ww  w  . java  2s . c  o  m*/
    }
    ApplicationContext context = testContext.getApplicationContext();
    if (context instanceof ConfigurableApplicationContext) {

        SeleniumTest annotation = findAnnotation(testContext.getTestClass(), SeleniumTest.class);
        webDriver = BeanUtils.instantiate(annotation.driver());

        ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) context;
        ConfigurableListableBeanFactory bf = configurableApplicationContext.getBeanFactory();
        bf.registerResolvableDependency(WebDriver.class, webDriver);
    }
}

From source file:org.jasig.portlet.calendar.util.MockWebApplicationContextLoader.java

public ApplicationContext loadContext(String... locations) throws Exception {
    // Establish the portlet context and config based on the test class's MockWebApplication annotation.
    MockServletContext mockServletContext = new MockServletContext(configuration.webapp(),
            new FileSystemResourceLoader());
    final ServletWrappingPortletContext portletContext = new ServletWrappingPortletContext(mockServletContext);
    final MockPortletConfig portletConfig = new MockPortletConfig(portletContext, configuration.name());

    // Create a WebApplicationContext and initialize it with the xml and portlet configuration.
    final XmlPortletApplicationContext portletApplicationContext = new XmlPortletApplicationContext();
    portletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            portletApplicationContext);//from w  ww .  j a v a 2  s . co m
    portletApplicationContext.setPortletConfig(portletConfig);
    portletApplicationContext.setConfigLocations(locations);

    // Create a DispatcherPortlet that uses the previously established WebApplicationContext.
    final DispatcherPortlet dispatcherPortlet = new DispatcherPortlet() {
        @Override
        protected WebApplicationContext createPortletApplicationContext(ApplicationContext parent) {
            return portletApplicationContext;
        }
    };

    final ViewResolver viewResolver = new MockViewResolver();

    // Add the DispatcherPortlet (and anything else you want) to the context.
    // Note: this doesn't happen until refresh is called below.
    portletApplicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.registerResolvableDependency(DispatcherPortlet.class, dispatcherPortlet);
            // Register any other beans here, including a ViewResolver if you are using JSPs.
            beanFactory.registerResolvableDependency(ViewResolver.class, viewResolver);
        }
    });

    // Have the context notify the portlet every time it is refreshed.
    portletApplicationContext.addApplicationListener(new SourceFilteringListener(portletApplicationContext,
            new ApplicationListener<ContextRefreshedEvent>() {
                public void onApplicationEvent(ContextRefreshedEvent event) {
                    dispatcherPortlet.onApplicationEvent(event);
                }
            }));

    // Prepare the context.
    portletApplicationContext.refresh();
    portletApplicationContext.registerShutdownHook();

    // Initialize the portlet.
    dispatcherPortlet.setContextConfigLocation("");
    dispatcherPortlet.init(portletConfig);

    return portletApplicationContext;
}

From source file:com.github.carlomicieli.nerdmovies.MockWebApplicationContextLoader.java

@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    final MockServletContext servletContext = new MockServletContext(configuration.webapp(),
            new FileSystemResourceLoader());
    final MockServletConfig servletConfig = new MockServletConfig(servletContext, configuration.name());

    final AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    webContext.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
    webContext.setServletConfig(servletConfig);
    webContext.setConfigLocations(mergedConfig.getLocations());
    webContext.register(mergedConfig.getClasses());

    // Create a DispatcherServlet that uses the previously established
    // WebApplicationContext.
    @SuppressWarnings("serial")
    final DispatcherServlet dispatcherServlet = new DispatcherServlet() {
        @Override/* w w  w  .  ja  va2s.c o  m*/
        protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
            return webContext;
        }
    };

    // Add the DispatcherServlet (and anything else you want) to the
    // context.
    // Note: this doesn't happen until refresh is called below.
    webContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.registerResolvableDependency(DispatcherServlet.class, dispatcherServlet);
            // Register any other beans here, including a ViewResolver if
            // you are using JSPs.
        }
    });

    // Have the context notify the servlet every time it is refreshed.
    webContext.addApplicationListener(
            new SourceFilteringListener(webContext, new ApplicationListener<ContextRefreshedEvent>() {
                @Override
                public void onApplicationEvent(ContextRefreshedEvent event) {
                    dispatcherServlet.onApplicationEvent(event);
                }
            }));

    // Prepare the context.
    webContext.refresh();
    webContext.registerShutdownHook();

    // Initialize the servlet.
    dispatcherServlet.setContextConfigLocation("");
    dispatcherServlet.init(servletConfig);

    return webContext;
}

From source file:org.everrest.spring.SpringComponentsLoader.java

/**
 * Add binding for HttpHeaders, InitialProperties, Request, SecurityContext, UriInfo. All this types will be
 * supported for injection in constructor or fields of component of Spring IoC container.
 *
 * @param beanFactory/*from   w  ww.  j a v  a2 s.  c om*/
 *         bean factory
 * @see org.springframework.beans.factory.annotation.Autowired
 */
protected void addAutowiredDependencies(ConfigurableListableBeanFactory beanFactory) {
    beanFactory.registerResolvableDependency(HttpHeaders.class, new ObjectFactory<HttpHeaders>() {
        @Override
        public HttpHeaders getObject() {
            ApplicationContext context = ApplicationContextImpl.getCurrent();
            if (context == null) {
                throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
            }
            return context.getHttpHeaders();
        }
    });
    beanFactory.registerResolvableDependency(InitialProperties.class, new ObjectFactory<InitialProperties>() {
        @Override
        public InitialProperties getObject() {
            ApplicationContext context = ApplicationContextImpl.getCurrent();
            if (context == null) {
                throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
            }
            return context.getInitialProperties();
        }
    });
    beanFactory.registerResolvableDependency(Request.class, new ObjectFactory<Request>() {
        @Override
        public Request getObject() {
            ApplicationContext context = ApplicationContextImpl.getCurrent();
            if (context == null) {
                throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
            }
            return context.getRequest();
        }
    });
    beanFactory.registerResolvableDependency(SecurityContext.class, new ObjectFactory<SecurityContext>() {
        @Override
        public SecurityContext getObject() {
            ApplicationContext context = ApplicationContextImpl.getCurrent();
            if (context == null) {
                throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
            }
            return context.getSecurityContext();
        }
    });
    beanFactory.registerResolvableDependency(UriInfo.class, new ObjectFactory<UriInfo>() {
        @Override
        public UriInfo getObject() {
            ApplicationContext context = ApplicationContextImpl.getCurrent();
            if (context == null) {
                throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
            }
            return context.getUriInfo();
        }
    });
    beanFactory.registerResolvableDependency(javax.ws.rs.core.Application.class,
            new ObjectFactory<javax.ws.rs.core.Application>() {
                @Override
                public javax.ws.rs.core.Application getObject() {
                    ApplicationContext context = ApplicationContextImpl.getCurrent();
                    if (context == null) {
                        throw new IllegalStateException("EverRest ApplicationContext is not initialized.");
                    }
                    return context.getApplication();
                }
            });
}

From source file:fi.eis.applications.osgi.support.OsgiBundleXmlWebApplicationContext.java

/**
 * {@inheritDoc}//from w  ww. j a v a 2 s. c  o  m
 * 
 * Registers request/session scopes, a {@link ServletContextAwareProcessor},
 * etc.
 */
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    super.postProcessBeanFactory(beanFactory);

    beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext, this.servletConfig));
    beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    beanFactory.ignoreDependencyInterface(ServletConfigAware.class);
    beanFactory.registerResolvableDependency(ServletContext.class, this.servletContext);
    beanFactory.registerResolvableDependency(ServletConfig.class, this.servletConfig);

    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory);
}

From source file:com.meidusa.venus.client.VenusServiceFactory.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    // register to resolvable dependency container
    if (beanFactory instanceof ConfigurableListableBeanFactory) {
        ConfigurableListableBeanFactory cbf = (ConfigurableListableBeanFactory) beanFactory;
        for (Map.Entry<Class<?>, Tuple<Object, RemotingInvocationHandler>> entry : servicesMap.entrySet()) {
            cbf.registerResolvableDependency(entry.getKey(), entry.getValue().left);
        }//from  w  w  w.  j ava  2  s  .  co m
        for (Map.Entry<String, Tuple<Object, RemotingInvocationHandler>> entry : serviceBeanMap.entrySet()) {
            cbf.registerSingleton(entry.getKey(), entry.getValue().left);
        }
    }
}

From source file:org.activiti.spring.components.scope.ProcessScope.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    beanFactory.registerScope(ProcessScope.PROCESS_SCOPE_NAME, this);

    Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory,
            "BeanFactory was not a BeanDefinitionRegistry, so ProcessScope cannot be used.");

    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        // Replace this or any of its inner beans with scoped proxy if it has this scope
        boolean scoped = PROCESS_SCOPE_NAME.equals(definition.getScope());
        Scopifier scopifier = new Scopifier(registry, PROCESS_SCOPE_NAME, proxyTargetClass, scoped);
        scopifier.visitBeanDefinition(definition);
        if (scoped) {
            Scopifier.createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }/*  ww w .  j  a  v a2 s  .  c  o m*/
    }

    beanFactory.registerSingleton(ProcessScope.PROCESS_SCOPE_PROCESS_VARIABLES_SINGLETON,
            this.processVariablesMap);
    beanFactory.registerResolvableDependency(ProcessInstance.class, createSharedProcessInstance());
}

From source file:ro.codecamp.ebp.core.util.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * Register request/session scopes, a {@link ServletContextAwareProcessor}, etc.
 * //from   w  w w  .j  a v a  2s  . c  o  m
 * @see WebApplicationContextUtils#registerWebApplicationScopes(ConfigurableListableBeanFactory)
 */
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    super.postProcessBeanFactory(beanFactory);

    // Drive the kernel's bean factory post processors.
    BundleContext bundleContext = getBundleContext();
    if (bundleContext != null) {
        ServiceReference sr = bundleContext.getServiceReference(OsgiBeanFactoryPostProcessor.class);
        if (sr != null) {
            OsgiBeanFactoryPostProcessor kernelPostProcessor = (OsgiBeanFactoryPostProcessor) bundleContext
                    .getService(sr);
            try {
                kernelPostProcessor.postProcessBeanFactory(bundleContext, beanFactory);
            } catch (Exception e) {
                throw new ApplicationContextException("Kernel bean factory post processor failed", e);
            } finally {
                bundleContext.ungetService(sr);
            }
        }
    }

    beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(getServletContext(), getServletConfig()));
    beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    beanFactory.ignoreDependencyInterface(ServletConfigAware.class);
    beanFactory.registerResolvableDependency(ServletContext.class, getServletContext());
    beanFactory.registerResolvableDependency(ServletConfig.class, getServletConfig());

    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory);
}

From source file:com.productone.spring.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * Register request/session scopes, a {@link ServletContextAwareProcessor},
 * etc./*from www . j ava2 s  . c  o  m*/
 *
 * @see
 * WebApplicationContextUtils#registerWebApplicationScopes(ConfigurableListableBeanFactory)
 */
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    super.postProcessBeanFactory(beanFactory);

    // Drive the kernel's bean factory post processors.
    BundleContext bundleContext = getBundleContext();
    if (bundleContext != null) {
        ServiceReference sr = bundleContext.getServiceReference(OsgiBeanFactoryPostProcessor.class.getName());
        if (sr != null) {
            OsgiBeanFactoryPostProcessor kernelPostProcessor = (OsgiBeanFactoryPostProcessor) bundleContext
                    .getService(sr);
            try {
                kernelPostProcessor.postProcessBeanFactory(bundleContext, beanFactory);
            } catch (Exception e) {
                throw new ApplicationContextException("Kernel bean factory post processor failed", e);
            } finally {
                bundleContext.ungetService(sr);
            }
        }
    }

    beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(getServletContext(), getServletConfig()));
    beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    beanFactory.ignoreDependencyInterface(ServletConfigAware.class);
    beanFactory.registerResolvableDependency(ServletContext.class, getServletContext());
    beanFactory.registerResolvableDependency(ServletConfig.class, getServletConfig());

    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory);
}