好好学习,天天向上!

sun.proxy.$Proxy0 cannot be cast to dao.impl.MyAdviceImpl

ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        MyAdviceImpl ad=(MyAdviceImpl) ac.getBean("ad");//类 FAIL
        ad.sayHello();

Exception in thread "main" java.lang.ClassCastException: sun.proxy.$Proxy0 cannot be cast to dao.impl.MyAdviceImpl
    at test.Test.main(Test.java:15)

经过百度和尝试 发现 需要把获取的bean 强制成 接口类型即可

ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        MyAdvice ad=(MyAdvice) ac.getBean("ad");//接口类型 SUCCESS
        ad.sayHello();

 

posted @ 2013-08-09 04:12  忍性而为  阅读(634)  评论(0编辑  收藏  举报
好好学习,天天向上!