List of usage examples for org.springframework.aop.framework ProxyFactory setProxyTargetClass
public void setProxyTargetClass(boolean proxyTargetClass)
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers beans that are configured for lazy initialization with the * <code>MBeanServer<code> indirectly through a proxy. * @param beanName the name of the bean in the <code>BeanFactory</code> * @param beanKey the key associated with this bean in the beans map * @return the <code>ObjectName</code> under which the bean was registered * with the <code>MBeanServer</code> * @throws JMException an error in the underlying JMX infrastructure * @throws InvalidTargetObjectTypeException an error in the definition of the MBean resource */// w w w . jav a 2s. c om private ObjectName registerLazyInit(String beanName, String beanKey) throws JMException, InvalidTargetObjectTypeException { LazyInitTargetSource targetSource = new LazyInitTargetSource(); targetSource.setTargetBeanName(beanName); targetSource.setBeanFactory(this.beanFactory); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(targetSource); proxyFactory.setProxyTargetClass(true); proxyFactory.setFrozen(true); Object proxy = proxyFactory.getProxy(); ObjectName objectName = getObjectName(proxy, beanKey); if (logger.isDebugEnabled()) { logger.debug("Registering lazy-init MBean [" + objectName + "]"); } ModelMBean mbean = createModelMBean(); mbean.setModelMBeanInfo(getMBeanInfo(proxy, beanKey)); mbean.setManagedResource(proxy, MR_TYPE_OBJECT_REFERENCE); return doRegister(mbean, objectName); }
From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java
/** * Create a refreshable proxy for the given AOP TargetSource. * @param ts the refreshable TargetSource * @param interfaces the proxy interfaces (may be {@code null} to * indicate proxying of all interfaces implemented by the target class) * @return the generated proxy/*from ww w . jav a 2 s .c om*/ * @see RefreshableScriptTargetSource */ protected Object createRefreshableProxy(TargetSource ts, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) { ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTargetSource(ts); ClassLoader classLoader = this.beanClassLoader; if (interfaces != null) { proxyFactory.setInterfaces(interfaces); } else { Class<?> targetClass = ts.getTargetClass(); if (targetClass != null) { proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.beanClassLoader)); } } if (proxyTargetClass) { classLoader = null; // force use of Class.getClassLoader() proxyFactory.setProxyTargetClass(true); } DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts); introduction.suppressInterface(TargetSource.class); proxyFactory.addAdvice(introduction); return proxyFactory.getProxy(classLoader); }