/** * Create a new ProxyCreatorSupport instance. */ public ProxyCreatorSupport() { this.aopProxyFactory = new DefaultAopProxyFactory(); }
@Override public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException { if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) { Class<?> targetClass = config.getTargetClass(); if (targetClass == null) { throw new AopConfigException("TargetSource cannot determine target class: " + "Either an interface or a target is required for proxy creation."); } if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) { return new JdkDynamicAopProxy(config); } return new ObjenesisCglibAopProxy(config); } else { return new JdkDynamicAopProxy(config); } }
@Before public void setup() { converter = new Jaxb2RootElementHttpMessageConverter(); rootElement = new RootElement(); DefaultAopProxyFactory proxyFactory = new DefaultAopProxyFactory(); AdvisedSupport advisedSupport = new AdvisedSupport(); advisedSupport.setTarget(rootElement); advisedSupport.setProxyTargetClass(true); AopProxy proxy = proxyFactory.createAopProxy(advisedSupport); rootElementCglib = (RootElement) proxy.getProxy(); }
Class<?>[] classes = {B.class}; AdvisedSupport config = new AdvisedSupport(classes); try { config.setTargetSource(((Advised) b).getTargetSource()); } catch (Exception e) { e.printStackTrace(); } for (Advisor advisor : ((Advised) b).getAdvisors()) { Advice advice = advisor.getAdvice(); if ((advice instanceof AbstractAspectJAdvice) && "advice.A2".equals( ((AbstractAspectJAdvice) advice).getAspectName())) { // Do not add A2 advisor } else { config.addAdvisor(advisor); } } DefaultAopProxyFactory factory = new DefaultAopProxyFactory(); B newB = (B)factory.createAopProxy(config).getProxy();
/** * Create a new ProxyCreatorSupport instance. */ public ProxyCreatorSupport() { this.aopProxyFactory = new DefaultAopProxyFactory(); }
@Override public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException { if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) { Class<?> targetClass = config.getTargetClass(); if (targetClass == null) { throw new AopConfigException("TargetSource cannot determine target class: " + "Either an interface or a target is required for proxy creation."); } if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) { return new JdkDynamicAopProxy(config); } return new ObjenesisCglibAopProxy(config); } else { return new JdkDynamicAopProxy(config); } }
/** * Create a new ProxyCreatorSupport instance. */ public ProxyCreatorSupport() { this.aopProxyFactory = new DefaultAopProxyFactory(); }
@Override public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException { if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) { Class<?> targetClass = config.getTargetClass(); if (targetClass == null) { throw new AopConfigException("TargetSource cannot determine target class: " + "Either an interface or a target is required for proxy creation."); } if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) { return new JdkDynamicAopProxy(config); } return new ObjenesisCglibAopProxy(config); } else { return new JdkDynamicAopProxy(config); } }
pf.setExposeProxy(false); pf.setFrozen(true); pf.setAopProxyFactory(new DefaultAopProxyFactory()); pf.setTargetSource(this.targetSource);