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();