- package cn.itcast.day3.aopframework;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Properties;
- import cn.itcast.day3.Advice;
- public class BeanFactory {
- Properties props = new Properties();
- public BeanFactory(InputStream ips)
- {
- try {
- props.load(ips);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public Object getBean(String name)
- {
- String className = props.getProperty(name);
- Object bean = null;
- try {
- Class clazz = Class.forName(className);
- bean = clazz.newInstance();
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(bean instanceof ProxyFactoryBean)
- {
- Object proxy = null;
- ProxyFactoryBean proxyFactoryBean = (ProxyFactoryBean)bean;
- try {
- Advice advice =(Advice)Class.forName(props.getProperty(name+".advice")).newInstance();
- Object target = Class.forName(props.getProperty(name+".target")).newInstance();;
- proxyFactoryBean.setAdvice(advice);
- proxyFactoryBean.setTarget(target);
- proxy = proxyFactoryBean.getProxy();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return proxy;
- }
- return bean;
- }
- }
复制代码- package cn.itcast.day3.aopframework;
- import java.io.InputStream;
- public class AopFrameworkTest {
- /**
- * @param args
- */
- public static void main(String[] args)throws Exception {
- // TODO Auto-generated method stub
- InputStream ips = AopFrameworkTest.class.getResourceAsStream("config.properties");
- Object bean = new BeanFactory(ips).getBean("xxx");
- System.out.println(bean.getClass().getName());
- }
- }
复制代码 上面是报告有错的代码。
这是报告的错误:
|
|