- public class BeanFactory {
- Properties props = new Properties();
- public BeanFactory(InputStream ips) {
- try {
- props.load(ips);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public Object getBean(String name) throws Exception{
-
- String className=props.getProperty(name);
- Class clazz=Class.forName(className);
- Object bean=clazz.newInstance();
- if(bean instanceof ProxyFactoryBean){
- ProxyFactoryBean proxyFactoryBean=(ProxyFactoryBean) bean;
-
- Advice advice=(Advice) Class.forName((String) props.get(name+".advice")).newInstance();
- Object taget=Class.forName((String) props.get(name+".advice")).newInstance() ; // 两个相同的代码。
-
- proxyFactoryBean.setAdvice(advice);
- proxyFactoryBean.setTaget(taget);
- Object proxy=(proxyFactoryBean).getProxy();
- return proxy;
- }
- return bean;
-
- }
- }
复制代码 首先我对于动态代理不是很了解,对于spring也是没明白,很简单 张老师在讲课中解释了上面代码的重复问题,,但是始终我没能够明白到底是什么问题造成了代码相同 也就是第二段代码也是".advice"也能够正常运行。
|