本帖最后由 吴清源 于 2013-9-3 10:17 编辑
- package com.wqYuan.test;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Properties;
- public class BeenFactory {
- Properties proes = new Properties();
- public BeenFactory(InputStream ips) {
- try {
- proes.load(ips);
- } catch (IOException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- }
- }
- public Object getBeen (String name){
- String className = proes.getProperty(name);
- Object bean = null;
- try {
- Class<?> clazz = Class.forName(className);
- bean = clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- }
- if (bean instanceof ProxyFactoryBean) {
- Object pro = null;
- ProxyFactoryBean proxy = (ProxyFactoryBean)bean;
- try {
- Advice advice = (Advice)Class.forName(proes.getProperty(className+".advice")).newInstance();
- Object target = Class.forName(proes.getProperty(className+".target")).newInstance();
- //System.out.println("utyhthtyj");
- proxy.setAdvice(advice);
- proxy.setTarget(target);
- } catch (InstantiationException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- }
- pro = proxy.getProxy();
- return pro;
- }
- return bean;
- }
- }
复制代码 这是BeanFactory的代码,运行main方法的时候提示advice空指针异常,我那配置文件没有写错啊
zzz=com.wqYuan.test.ProxyFactoryBean
zzz.target=java.util.ArrayList
zzz.advice=com.wqYuan.test.MyAdvice
传进去的字符串名称也是zzz。
|