A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. package cn.itcast.day3.aopframework;      

  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.util.Properties;

  5. import cn.itcast.day3.Advice;


  6. public class BeanFactory {
  7. Properties props = new Properties();
  8. public BeanFactory(InputStream ips)
  9. {
  10. try {
  11. props.load(ips);
  12. } catch (IOException e) {
  13. // TODO Auto-generated catch block
  14. e.printStackTrace();
  15. }
  16. }
  17. public Object getBean(String name)
  18. {
  19. String className = props.getProperty(name);
  20. Object bean = null;
  21. try {
  22. Class clazz = Class.forName(className);
  23. bean = clazz.newInstance();
  24. } catch (Exception e) {

  25. e.printStackTrace();
  26. }
  27. if(bean instanceof ProxyFactoryBean)
  28. {
  29. Object proxy = null;
  30. ProxyFactoryBean proxyFactoryBean = (ProxyFactoryBean)bean;
  31. try {
  32. Advice advice =(Advice)Class.forName(props.getProperty(name+".advice")).newInstance();
  33. Object target = Class.forName(props.getProperty(name+".target")).newInstance();;
  34. proxyFactoryBean.setAdvice(advice);
  35. proxyFactoryBean.setTarget(target);
  36. proxy = proxyFactoryBean.getProxy();
  37. } catch (Exception e) {
  38. // TODO Auto-generated catch block
  39. e.printStackTrace();
  40. }
  41. return proxy;
  42. }
  43. return bean;

  44. }
  45. }
复制代码
  1. package cn.itcast.day3.aopframework;

  2. import java.io.InputStream;

  3. public class AopFrameworkTest {

  4. /**
  5. * @param args
  6. */
  7. public static void main(String[] args)throws Exception {
  8. // TODO Auto-generated method stub
  9. InputStream ips = AopFrameworkTest.class.getResourceAsStream("config.properties");
  10. Object bean = new BeanFactory(ips).getBean("xxx");
  11. System.out.println(bean.getClass().getName());
  12. }

  13. }
复制代码
上面是报告有错的代码。
   这是报告的错误

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马