当前位置:
首页 >
AOP的相关代理
发布时间:2025/4/16
49
豆豆
在没有使用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表达