Skip to content

Commit

Permalink
Merge pull request DerekYRC#26 from FreeSlaver/instantiation-strategy
Browse files Browse the repository at this point in the history
implement cglib instantiation strategy
  • Loading branch information
DerekYRC authored Jun 23, 2022
2 parents bf88d6a + 4cd9cd8 commit be8f86f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.springframework.beans.factory.support;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;

Expand All @@ -18,7 +20,9 @@ public class CglibSubclassingInstantiationStrategy implements InstantiationStrat
*/
@Override
public Object instantiate(BeanDefinition beanDefinition) throws BeansException {
//TODO 感兴趣的小伙伴可以实现下
throw new UnsupportedOperationException("CGLIB instantiation strategy is not supported");
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(beanDefinition.getBeanClass());
enhancer.setCallback((MethodInterceptor) (obj, method, argsTemp, proxy) -> proxy.invokeSuper(obj,argsTemp));
return enhancer.create();
}
}

0 comments on commit be8f86f

Please sign in to comment.