河南省_downFile_spring cglib和jdk动态代理

@SpringBootApplication
@Slf4j
// 指示是否创建基于子类(CGLIB)的代理,而不是创建基于标准Java接口的代理。 默认值是{@code false}。
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SpringAopApplicationDemo implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpringAopApplicationDemo.class, args);
    }

    // 定义切面,或者直接使用@Component注解
    @Bean
    public FooAspect fooAspect() {
        return new FooAspect();
    }

    // 有接口实现
    @Autowired
    LoginService loginService;

    // 无接口实现
    @Autowired
    PlainLoginService plainLoginService;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        log.info(loginService.getClass().toString()); // class io.spring.action.aop.service.impl.LoginServiceImpl$$EnhancerBySpringCGLIB$$d3171a1f
        loginService.login();

        log.info(plainLoginService.getClass().toString()); // class io.spring.action.aop.service.PlainLoginService$$EnhancerBySpringCGLIB$$5b51dab3
        plainLoginService.login();
    }
}
@Configuration
@ComponentScan
@EnableAspectJAutoProxy(proxyTargetClass = false)
@Slf4j
public class SpringApplicationDemo {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringApplicationDemo.class);

        LoginService loginService = context.getBean(LoginService.class); //jdk
        PlainLoginService plainLoginService = context.getBean(PlainLoginService.class); // cglib
        log.info("jdk class name = {}", loginService.getClass()); 
        log.info("cglib class name = {}", plainLoginService.getClass()); 
    }

    @Autowired
    private LoginService loginService;

    // 定义切面,或者直接使用@Component注解
    @Bean
    public FooAspect fooAspect() {
        return new FooAspect();
    }
}

@Configuration
@ComponentScan
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Slf4j
public class SpringApplicationDemo {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringApplicationDemo.class);

        LoginService loginService = context.getBean(LoginService.class); //jdk
        PlainLoginService plainLoginService = context.getBean(PlainLoginService.class); // cglib
        log.info("jdk class name = {}", loginService.getClass());
        log.info("cglib class name = {}", plainLoginService.getClass());

    }

    //Bean named 'loginServiceImpl' is expected to be of type 'io.spring.action.aop.service.impl.LoginServiceImpl' but was actually of type 'com.sun.proxy.$Proxy21'
    // **AOP代理对象如果使用jdk代理,只能赋值给接口,不能赋值给实现**
    //|||焦作市https://henansheng_jiaozuo>>郑州市https://henansheng_zhenzhoushi>>安阳市https://henansheng_anyangshi>>洛阳市https://henansheng_luoyangshi>>x新乡https://henansheng_xinxiangshi|||

    // SpringBoot中出于这个考虑,将所有代理对象默认为cglib
    @Autowired
	private LoginServiceImpl loginService;

    // 定义切面,或者直接使用@Component注解
    @Bean
    public FooAspect fooAspect() {
        return new FooAspect();
    }
}




org.csource.common.MyException: getStoreStorage fail, errno code: 2 at org.csource.fastdfs.StorageClient.newReadableStorageConnection(StorageClient.java:1767) at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1219) at org.csource.fastdfs.StorageClient.download_file(StorageClient.java:1206) at com.wzdigit.framework.utils.FastDFSUtil.downFile(FastDFSUtil.java:209) at com.wzdigit.srm.dsr.utils.FileUtil.getSingleFile(FileUtil.java:51) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService.getVendorQuotation(BiddingorderService.java:796) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService.sendEmail(BiddingorderService.java:746) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$FastClassBySpringCGLIB$$ebfcbd5a.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:73) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$EnhancerBySpringCGLIB$$80ace30.sendEmail(<generated>) at com.wzdigit.srm.dsr.service.bidding.BiddingorderService$$FastClassBySpringCGLIB$$ebfcbd5a.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值