Example usage for org.springframework.beans.factory BeanFactoryUtils beanOfTypeIncludingAncestors

List of usage examples for org.springframework.beans.factory BeanFactoryUtils beanOfTypeIncludingAncestors

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanFactoryUtils beanOfTypeIncludingAncestors.

Prototype

public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type) throws BeansException 

Source Link

Document

Return a single bean of the given type or subtypes, also picking up beans defined in ancestor bean factories if the current bean factory is a HierarchicalBeanFactory.

Usage

From source file:org.cloudfoundry.tools.timeout.TimeoutResourceHttpRequestHandler.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    this.timeoutValues = BeanFactoryUtils.beanOfTypeIncludingAncestors(event.getApplicationContext(),
            TimeoutValues.class);
}

From source file:com.leixl.easyframework.web.filter.VcaptchaFilter.java

public void init(FilterConfig config) throws ServletException {
    WebApplicationContext appCtx = WebApplicationContextUtils
            .getWebApplicationContext(config.getServletContext());
    captchaService = (ImageCaptchaService) BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx,
            ImageCaptchaService.class);
    session = (SessionProvider) BeanFactoryUtils.beanOfTypeIncludingAncestors(appCtx, SessionProvider.class);

    initIncludeURIs(config);// ww w.j  av a 2 s  .c  om
    initResultJson();
}

From source file:com.gzj.tulip.load.context.RoseAppContext.java

/**
 *  Bean, ? {@link ApplicationContext}  Bean.
 * //  ww  w  . j  av  a 2  s. co  m
 * @param beanType - Bean 
 * 
 * @throws BeansException
 */
public <T> T getBean(Class<T> beanType) throws BeansException {
    return beanType.cast(BeanFactoryUtils.beanOfTypeIncludingAncestors(this, beanType));
}

From source file:org.brixcms.rmiserver.boot.BootstrapperFactoryBean.java

public void afterPropertiesSet() throws Exception {
    LocalSessionFactoryBean hsf = (LocalSessionFactoryBean) BeanFactoryUtils.beanOfTypeIncludingAncestors(ctx,
            LocalSessionFactoryBean.class);
    Bootstrapper bootstrapper = new Bootstrapper(dataSource, transactionManager, hsf.getConfiguration(),
            sessionFactory, userService, workspaceManagerLogin, workspaceManagerPassword);
    bootstrapper.bootstrap();/*from  w  w w  .j  a v a  2 s  .  c o  m*/
}

From source file:com.googlecode.jsonrpc4j.spring.AbstractCompositeJsonServiceExporter.java

/**
 * {@inheritDoc}//from  ww w  .  j  a v  a  2s.c  o m
 */
public final void afterPropertiesSet() throws Exception {

    // find the ObjectMapper
    if (objectMapper == null && applicationContext != null && applicationContext.containsBean("objectMapper")) {
        objectMapper = (ObjectMapper) applicationContext.getBean("objectMapper");
    }
    if (objectMapper == null && applicationContext != null) {
        try {
            objectMapper = (ObjectMapper) BeanFactoryUtils.beanOfTypeIncludingAncestors(applicationContext,
                    ObjectMapper.class);
        } catch (Exception e) {
            /* no-op */ }
    }
    if (objectMapper == null) {
        objectMapper = new ObjectMapper();
    }

    // create the service
    Object service = ProxyUtil.createCompositeServiceProxy(getClass().getClassLoader(), services,
            serviceInterfaces, allowMultipleInheritance);

    // create the server
    jsonRpcServer = new JsonRpcServer(objectMapper, service);
    jsonRpcServer.setErrorResolver(errorResolver);
    jsonRpcServer.setBackwardsComaptible(backwardsComaptible);
    jsonRpcServer.setRethrowExceptions(rethrowExceptions);
    jsonRpcServer.setAllowExtraParams(allowExtraParams);
    jsonRpcServer.setAllowLessParams(allowLessParams);

    // export
    exportService();
}

From source file:org.brixcms.rmiserver.web.dav.WebDavServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    final ServletContext sc = config.getServletContext();
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(sc);
    if (context == null) {
        throw new IllegalStateException("Could not find application context");
    }/*from  w  w w  .j  a v  a 2s . co  m*/

    repository = (Repository) BeanFactoryUtils.beanOfTypeIncludingAncestors(context, Repository.class);
    if (repository == null) {
        throw new IllegalStateException("Could not find JackRabbit repository in spring context");
    }

    UserService users = (UserService) BeanFactoryUtils.beanOfTypeIncludingAncestors(context, UserService.class);
    if (repository == null) {
        throw new IllegalStateException("Could not find UserService implementation in spring context");
    }

    authorizer = new Authorizer(users);
    credentialsProvider = getCredentialsProvider();
}

From source file:com.googlecode.jsonrpc4j.spring.AbstractJsonServiceExporter.java

/**
 * {@inheritDoc}//from  www.  j a v a2s  . c o m
 */
public void afterPropertiesSet() throws Exception {

    // find the ObjectMapper
    if (objectMapper == null && applicationContext != null && applicationContext.containsBean("objectMapper")) {
        objectMapper = (ObjectMapper) applicationContext.getBean("objectMapper");
    }
    if (objectMapper == null && applicationContext != null) {
        try {
            objectMapper = (ObjectMapper) BeanFactoryUtils.beanOfTypeIncludingAncestors(applicationContext,
                    ObjectMapper.class);
        } catch (Exception e) {
            /* no-op */ }
    }
    if (objectMapper == null) {
        objectMapper = new ObjectMapper();
    }

    // create the server
    jsonRpcServer = new JsonRpcServer(objectMapper, getProxyForService(), getServiceInterface());
    jsonRpcServer.setErrorResolver(errorResolver);
    jsonRpcServer.setBackwardsComaptible(backwardsComaptible);
    jsonRpcServer.setRethrowExceptions(rethrowExceptions);
    jsonRpcServer.setAllowExtraParams(allowExtraParams);
    jsonRpcServer.setAllowLessParams(allowLessParams);
    jsonRpcServer.setExceptionLogLevel(exceptionLogLevel);
    jsonRpcServer.setInvocationListener(invocationListener);

    // export
    exportService();
}

From source file:com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean.java

/**
 * {@inheritDoc}/*from w  ww .j a  v  a 2 s  .c  om*/
 */
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
    super.afterPropertiesSet();

    // create proxy
    proxyObject = ProxyFactory.getProxy(getServiceInterface(), this);

    // find the ObjectMapper
    if (objectMapper == null && applicationContext != null && applicationContext.containsBean("objectMapper")) {
        objectMapper = (ObjectMapper) applicationContext.getBean("objectMapper");
    }
    if (objectMapper == null && applicationContext != null) {
        try {
            objectMapper = (ObjectMapper) BeanFactoryUtils.beanOfTypeIncludingAncestors(applicationContext,
                    ObjectMapper.class);
        } catch (Exception e) {
            /* no-op */ }
    }
    if (objectMapper == null) {
        objectMapper = new ObjectMapper();
    }

    // create JsonRpcHttpClient
    try {
        jsonRpcHttpClient = new JsonRpcHttpClient(objectMapper, new URL(getServiceUrl()), extraHttpHeaders);
        jsonRpcHttpClient.setRequestListener(requestListener);
    } catch (MalformedURLException mue) {
        throw new RuntimeException(mue);
    }
}

From source file:net.daum.clix.springframework.data.rest.client.repository.RestRepositories.java

/**
 * Creates a new {@link RestRepositories} instance by looking up the
 * repository instances and meta information from the given
 * {@link ListableBeanFactory}./* w  w  w.  jav  a  2s . co m*/
 * 
 * @param factory
 *            must not be {@literal null}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public RestRepositories(ListableBeanFactory factory) {

    Assert.notNull(factory);

    Collection<RestRepositoryFactoryBean> providers = BeanFactoryUtils
            .beansOfTypeIncludingAncestors(factory, RestRepositoryFactoryBean.class, true, false).values();

    for (RepositoryFactoryInformation<Object, Serializable> info : providers) {

        RepositoryInformation information = info.getRepositoryInformation();
        Class repositoryInterface = information.getRepositoryInterface();

        if (CrudRepository.class.isAssignableFrom(repositoryInterface)) {
            Class<CrudRepository<Object, Serializable>> objectType = repositoryInterface;
            CrudRepository<Object, Serializable> repository = BeanFactoryUtils
                    .beanOfTypeIncludingAncestors(factory, objectType);

            this.domainClassToBeanName.put(information.getDomainType(), info);
            this.resourcePathToBeanName.put(getResourcePath(repositoryInterface), info);
            this.repositories.put(info, repository);

        }
    }
}