當前位置:
首頁 >
AOP的相关代理
發布時間:2025/4/16
42
豆豆
在沒有使用aop的情況下 :class cn.dym.service.impl.UserServiceImpl當使用了aop的情況下:class com.sun.proxy.$Proxy19jdk代理所產生的一個動態代理類,當被代理的類實現了接口會默認使用jdk代理
class cn.dym.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$f281cf64cglib代理所所產生的一個動態代理類,當被代理的類沒有實現接口就會使用cglib代理
package cn.dym.tests;import cn.dym.service.IUserService; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringTest {@Testpublic void test() throws Exception {ClassPathXmlApplicationContext ioc=new ClassPathXmlApplicationContext("classpath:/spring.xml");IUserService bean = (IUserService) ioc.getBean(IUserService.class);System.out.println(bean.getClass());} }
package cn.dym.tests;import cn.dym.service.IUserService; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringTest {@Testpublic void test() throws Exception {ClassPathXmlApplicationContext ioc=new ClassPathXmlApplicationContext("classpath:/spring.xml");IUserService bean = (IUserService) ioc.getBean(IUserService.class);System.out.println(bean.getClass());} }
?
bean的獲取方式:要么通過接口去獲取;要么通過名字去獲取
總結
- 上一篇: Sharding Sphere 读写分离
- 下一篇: AOP切入点表达式 ——within表达