Search in sources :

Example 1 with ProxyFactoryBean

use of org.springframework.aop.framework.ProxyFactoryBean in project spring-security by spring-projects.

the class AuthenticationConfiguration method lazyBean.

@SuppressWarnings("unchecked")
private <T> T lazyBean(Class<T> interfaceName) {
    LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource();
    String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, interfaceName);
    if (beanNamesForType.length == 0) {
        return null;
    }
    Assert.isTrue(beanNamesForType.length == 1, "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType));
    lazyTargetSource.setTargetBeanName(beanNamesForType[0]);
    lazyTargetSource.setBeanFactory(applicationContext);
    ProxyFactoryBean proxyFactory = new ProxyFactoryBean();
    proxyFactory = objectPostProcessor.postProcess(proxyFactory);
    proxyFactory.setTargetSource(lazyTargetSource);
    return (T) proxyFactory.getObject();
}
Also used : ProxyFactoryBean(org.springframework.aop.framework.ProxyFactoryBean) LazyInitTargetSource(org.springframework.aop.target.LazyInitTargetSource)

Aggregations

ProxyFactoryBean (org.springframework.aop.framework.ProxyFactoryBean)1 LazyInitTargetSource (org.springframework.aop.target.LazyInitTargetSource)1