List of usage examples for org.springframework.util ClassUtils isCglibProxyClass
@Deprecated public static boolean isCglibProxyClass(@Nullable Class<?> clazz)
From source file:org.solmix.runtime.exchange.support.SpringAopClassHelper.java
@Override protected Class<?> getRealClassFromClassInternal(Class<?> cls) { if (ClassUtils.isCglibProxyClass(cls)) { return getRealClassFromClassInternal(cls.getSuperclass()); }//ww w . ja v a2 s. c om return cls; }
From source file:org.spring.guice.module.SpringModule.java
@Override public void configure(Binder binder) { for (String name : beanFactory.getBeanDefinitionNames()) { BeanDefinition definition = beanFactory.getBeanDefinition(name); if (definition.isAutowireCandidate() && definition.getRole() == AbstractBeanDefinition.ROLE_APPLICATION) { Class<?> type = beanFactory.getType(name); @SuppressWarnings("unchecked") final Class<Object> cls = (Class<Object>) type; final String beanName = name; Provider<Object> provider = new BeanFactoryProvider(beanFactory, beanName, type); if (!cls.isInterface() && !ClassUtils.isCglibProxyClass(cls)) { bindConditionally(binder, name, cls, provider); }//w w w . ja v a 2s . c o m for (Class<?> iface : ClassUtils.getAllInterfacesForClass(cls)) { @SuppressWarnings("unchecked") Class<Object> unchecked = (Class<Object>) iface; bindConditionally(binder, name, unchecked, provider); } } } }
From source file:org.solmix.runtime.exchange.support.SpringAopClassHelper.java
@Override protected Class<?> getRealClassInternal(Object o) { if (AopUtils.isAopProxy(o) && (o instanceof Advised)) { Advised advised = (Advised) o;// w ww. j av a 2 s .co m try { TargetSource targetSource = advised.getTargetSource(); Object target = null; try { target = targetSource.getTarget(); } catch (BeanCreationException ex) { // some scopes such as 'request' may not // be active on the current thread yet return getRealClassFromClassInternal(targetSource.getTargetClass()); } if (target == null) { Class<?> targetClass = AopUtils.getTargetClass(o); if (targetClass != null) { return getRealClassFromClassInternal(targetClass); } } else { return getRealClassInternal(target); } } catch (Exception ex) { // ignore } } else if (ClassUtils.isCglibProxyClass(o.getClass())) { return getRealClassFromClassInternal(AopUtils.getTargetClass(o)); } return o.getClass(); }
From source file:io.neba.core.selftests.SelftestRegistrar.java
/** * Since proxies may implement a type's signature but not include a type's * annotations, we need to unproxy types before scanning for annotations. *///from w ww .j av a 2 s . c om private Class<?> unproxy(Class<?> beanType) { Class<?> unproxiedType = beanType; if (ClassUtils.isCglibProxyClass(beanType)) { // It is a dynamic subclass re-implementing the same methods. unproxiedType = beanType.getSuperclass(); } return unproxiedType; }
From source file:org.springframework.aop.framework.CglibAopProxy.java
@Override public Object getProxy(@Nullable ClassLoader classLoader) { if (logger.isDebugEnabled()) { logger.debug("Creating CGLIB proxy: target source is " + this.advised.getTargetSource()); }// w ww. j a v a2 s . c o m try { Class<?> rootClass = this.advised.getTargetClass(); Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy"); Class<?> proxySuperClass = rootClass; if (ClassUtils.isCglibProxyClass(rootClass)) { proxySuperClass = rootClass.getSuperclass(); Class<?>[] additionalInterfaces = rootClass.getInterfaces(); for (Class<?> additionalInterface : additionalInterfaces) { this.advised.addInterface(additionalInterface); } } // Validate the class, writing log messages as necessary. validateClassIfNecessary(proxySuperClass, classLoader); // Configure CGLIB Enhancer... Enhancer enhancer = createEnhancer(); if (classLoader != null) { enhancer.setClassLoader(classLoader); if (classLoader instanceof SmartClassLoader && ((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) { enhancer.setUseCache(false); } } enhancer.setSuperclass(proxySuperClass); enhancer.setInterfaces(AopProxyUtils.completeProxiedInterfaces(this.advised)); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setStrategy(new ClassLoaderAwareUndeclaredThrowableStrategy(classLoader)); Callback[] callbacks = getCallbacks(rootClass); Class<?>[] types = new Class<?>[callbacks.length]; for (int x = 0; x < types.length; x++) { types[x] = callbacks[x].getClass(); } // fixedInterceptorMap only populated at this point, after getCallbacks call above enhancer.setCallbackFilter(new ProxyCallbackFilter(this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset)); enhancer.setCallbackTypes(types); // Generate the proxy class and create a proxy instance. return createProxyClassAndInstance(enhancer, callbacks); } catch (CodeGenerationException | IllegalArgumentException ex) { throw new AopConfigException( "Could not generate CGLIB subclass of class [" + this.advised.getTargetClass() + "]: " + "Common causes of this problem include using a final class or a non-visible class", ex); } catch (Throwable ex) { // TargetSource.getTarget() failed throw new AopConfigException("Unexpected AOP exception", ex); } }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
/** * @since 3.2.8 and 4.0.2/*from ww w . ja v a 2s. c o m*/ * @see <a href="https://jira.spring.io/browse/SPR-10785">SPR-10785</a> and <a * href="https://jira.spring.io/browse/SPR-11420">SPR-11420</a> */ @Test public void methodInjectedBeanMustBeOfSameEnhancedCglibSubclassTypeAcrossBeanFactories() { Class<?> firstClass = null; for (int i = 0; i < 10; i++) { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(OVERRIDES_CONTEXT); final Class<?> currentClass = bf.getBean("overrideOneMethod").getClass(); assertTrue("Method injected bean class [" + currentClass + "] must be a CGLIB enhanced subclass.", ClassUtils.isCglibProxyClass(currentClass)); if (firstClass == null) { firstClass = currentClass; } else { assertEquals(firstClass, currentClass); } } }