Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Last active June 9, 2018 21:25
Show Gist options
  • Select an option

  • Save wreulicke/0dad59302d9da41ebafd07fb26f14412 to your computer and use it in GitHub Desktop.

Select an option

Save wreulicke/0dad59302d9da41ebafd07fb26f14412 to your computer and use it in GitHub Desktop.
SpringのProxy周りの実装を追いかける
  • AopAutoConfiguration

  • EnableAspectJAutoProxy

  • AspectJAutoProxyRegistrar

  • AopConfigUtils#registerAspectJAnnotationAutoProxyCreatorIfNecessary

  • AopConfigUtils#registerOrEscalateApcAsRequired

  • AnnotationAwareAspectJAutoProxyCreator.class <--> AspectJAwareAdvisorAutoProxyCreator.class

  • static { APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class); APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class); APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class); }

	@Override
	protected boolean isInfrastructureClass(Class<?> beanClass) {
		// Previously we setProxyTargetClass(true) in the constructor, but that has too
		// broad an impact. Instead we now override isInfrastructureClass to avoid proxying
		// aspects. I'm not entirely happy with that as there is no good reason not
		// to advise aspects, except that it causes advice invocation to go through a
		// proxy, and if the aspect implements e.g the Ordered interface it will be
		// proxied by that interface and fail at runtime as the advice method is not
		// defined on the interface. We could potentially relax the restriction about
		// not advising aspects in the future.
		return (super.isInfrastructureClass(beanClass) || this.aspectJAdvisorFactory.isAspect(beanClass));
	}
  • BeanFactoryAdvisorRetrievalHelper

  • ProxyCreationContext

  • AbstractAutoProxyCreator

    • SmartInstantiationAwareBeanPostProcessor
      • InstantiationAwareBeanPostProcessor
        • BeanPostProcessor
  • AbstractAutoProxyCreator

  • AbstractAutoProxyCreator#wrapIfNecessary

  • AbstractAutoProxyCreator#createProxy

  • ProxyConfig <-- AdvisedSupport <-- ProxyCreatorSupport <-- ProxyFactory

    • ProxyFactory#getProxy
    • ProxyCreatorSupport#createAopProxy
    • ProxyCreatorSupport#getAopProxyFactory
    • ProxyCreatorSupport#getAopProxyFactory
    • AopProxyFactory#createAopProxy
    • AopProxy#getProxy
    • DefaultAopProxyFactory#createAopProxy
      • JdkDynamicAopProxy(config);
      • ObjenesisCglibAopProxy(config);
      • JdkDynamicAopProxy(config);
    • ObjenesisCglibAopProxy#createProxyClassAndInstance
    • org.springframework.cglib.proxy.Enhancer#createClass
    • objenesis.newInstance(proxyClass, enhancer.getUseCache())
      • SpringObjenesis objenesis = new SpringObjenesis();
    • StdInstantiatorStrategy
      public <T> ObjectInstantiator<T> newInstantiatorOf(Class<T> type) {
          if (!PlatformDescription.isThisJVM("Java HotSpot") && !PlatformDescription.isThisJVM("OpenJDK")) {
              if (PlatformDescription.isThisJVM("Dalvik")) {
                  if (PlatformDescription.isAndroidOpenJDK()) {
                      return new UnsafeFactoryInstantiator(type);
                  } else if (PlatformDescription.ANDROID_VERSION <= 10) {
                      return new Android10Instantiator(type);
                  } else {
                      return (ObjectInstantiator)(PlatformDescription.ANDROID_VERSION <= 17 ? new Android17Instantiator(type) : new Android18Instantiator(type));
                  }
              } else if (PlatformDescription.isThisJVM("BEA")) {
                  return new SunReflectionFactoryInstantiator(type);
              } else if (PlatformDescription.isThisJVM("GNU libgcj")) {
                  return new GCJInstantiator(type);
              } else {
                  return (ObjectInstantiator)(PlatformDescription.isThisJVM("PERC") ? new PercInstantiator(type) : new UnsafeFactoryInstantiator(type));
              }
          } else if (PlatformDescription.isGoogleAppEngine() && PlatformDescription.SPECIFICATION_VERSION.equals("1.7")) {
              return (ObjectInstantiator)(Serializable.class.isAssignableFrom(type) ? new ObjectInputStreamInstantiator(type) : new AccessibleInstantiator(type));
          } else {
              return new SunReflectionFactoryInstantiator(type);
          }
  • TargetClassAware <-- Advised <--implements-- AdvisedSupport

  • DefaultAopProxyFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment