Java Code Examples for org.springframework.aop.framework.ProxyFactoryBean#setTarget()

The following examples show how to use org.springframework.aop.framework.ProxyFactoryBean#setTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyFactoryBeanConfig.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public ProxyFactoryBean transferService(){
	ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
	proxyFactoryBean.setTarget(new TransferServiceImpl());
	proxyFactoryBean.addAdvisor(transferServiceAdvisor());
	proxyFactoryBean.setExposeProxy(true);
	return proxyFactoryBean;
}
 
Example 2
Source File: ExecutorBeanPostProcessor.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
private <T extends Executor> Object proxify(T executor, BiFunction<T, Tracer, T> tracingExecutorProvider, boolean useCglib) {
  ProxyFactoryBean factory = new ProxyFactoryBean();
  factory.setProxyTargetClass(useCglib);
  factory.addAdvice(new ExecutorMethodInterceptor<>(executor, tracingExecutorProvider, tracer));
  factory.setTarget(executor);
  return factory.getObject();
}
 
Example 3
Source File: TraceMessagingAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
Object createProxy(Object bean) {
	ProxyFactoryBean factory = new ProxyFactoryBean();
	factory.setProxyTargetClass(true);
	factory.addAdvice(
			new MessageListenerMethodInterceptor(this.kafkaTracing, this.tracer));
	factory.setTarget(bean);
	return factory.getObject();
}
 
Example 4
Source File: ExecutorBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
Object createProxy(Object bean, boolean cglibProxy, Advice advice) {
	ProxyFactoryBean factory = new ProxyFactoryBean();
	factory.setProxyTargetClass(cglibProxy);
	factory.addAdvice(advice);
	factory.setTarget(bean);
	return getObject(factory);
}
 
Example 5
Source File: ExecutorBeanPostProcessor.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
Object createProxy(Object bean, boolean cglibProxy, Advice advice) {
    ProxyFactoryBean factory = new ProxyFactoryBean();
    factory.setProxyTargetClass(cglibProxy);
    factory.addAdvice(advice);
    factory.setTarget(bean);
    return getObject(factory);
}
 
Example 6
Source File: AutoProxyBeanFactory.java    From framework with Apache License 2.0 4 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author yang.zhipeng <br>
 * @taskId <br>
 * @param beanFactory <br>
 * @throws BeansException <br>
 */
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
    logger.info("*************************Dao注入列表***************************");
    SQLHandler sqlHandler = new SQLHandler();
    sqlHandler.setDaoConfig(config);

    ICache cache = CacheHelper.getCache();
    cache.removeNode(CacheConstant.SQL_PARAM_DIR);
    cache.removeNode(CacheConstant.SQL_DIR);

    try {
        for (String pack : packagesToScan) {
            if (StringUtils.isNotEmpty(pack)) {
                Set<Class<?>> clazzSet = BeanUtil.getClasses(pack);
                String className = null;
                for (Class<?> clazz : clazzSet) {
                    if (clazz.isAnnotationPresent(Dao.class)) {
                        className = clazz.getName();
                        String beanName = StringUtils.uncapitalize(clazz.getSimpleName());
                        if (beanFactory.containsBean(beanName)) {
                            beanName = className;
                            if (beanFactory.containsBean(beanName)) {
                                continue;
                            }
                        }

                        // 此处不缓存SQL
                        sqlHandler.invoke(clazz);

                        // 单独加载一个接口的代理类
                        ProxyFactoryBean factoryBean = new ProxyFactoryBean();
                        factoryBean.setBeanFactory(beanFactory);
                        factoryBean.setInterfaces(clazz);
                        factoryBean.setInterceptorNames(interceptors);
                        factoryBean.setTarget(getDaoHandler(clazz));
                        beanFactory.registerSingleton(beanName, factoryBean);
                        logger.info("    success create interface [{0}] with name {1}", className, beanName);
                    }
                }
            }
        }
    }
    catch (Exception e) {
        logger.error("------->自动扫描jar包失败", e);
    }
    logger.info("***********************************************************");
}