posts - 64,comments - 22,trackbacks - 0
一.使用默认的类构造器
1 <bean id="PersonService" class="com.wzy.service.impl.PersonServiceImpl"></bean>
接口类:
1 public interface PersonService {
2 
3     public abstract void print();
4 
5 }
实现类:
1 public class PersonServiceImpl implements PersonService {
2     public void print(){
3         System.out.println("Hello Spring!!!");
4     }
5 
6 }
二.使用静态工厂
1 <bean id="PersonServiceFactoryBean" class="com.wzy.service.PersonServiceFactoryBean" factory-method="personServiceFactory"></bean>
工厂类:
1 public class PersonServiceFactoryBean {
2     public static PersonService personServiceFactory(){
3         return new PersonServiceImpl();
4     }
5 }
三.使用实例工厂
1 <bean id="PersonFactoryBean" class="com.wzy.service.PersonServiceFactoryBean"></bean>
2            <bean id="PersonService2" factory-bean="PersonFactoryBean" factory-method="PersonServiceFactory2"></bean>
3 
工厂类
1 public class PersonServiceFactoryBean{    
2     public PersonService PersonServiceFactory2(){
3         return new PersonServiceImpl();
4     }
5 }
6 

















posted on 2011-11-19 15:02 hellxoul 阅读(221) 评论(0)  编辑  收藏 所属分类: Spring2.5

只有注册用户登录后才能发表评论。


网站导航: