Spring 实例化Bean

<?xml version="1.0" encoding="gb2312"?>

<!-- default-lazy-init="true" 为beans下所有的进行延迟初始化 -->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >
       <!-- id 不能是特殊字符,如:“/”,如果有特殊字符则应该用name。      交给Spring管理的Bean类-->
      
       <!--默认情况下(没有配置scope属性)是单实例  指的是每次获取Bean都是同一个对象  初始化容器时候就实例化实例化 PersonService
          可是使用lazy-init="true" 进行延迟初始化 ,即第一次获取bean的时候才初始化
           scope="prototype"每次获取Bean都是新的对象   第一次请求(调用getBean)的时候实例化 PersonService  .
           init-method="" 初始化 方法。即当bean被初始化后接下来会继续执行的方法。
           destroy-method=""
           -->
       <bean id="personService" class="com.milo.services.impl.PersonServiceBean" 
         lazy-init="false" init-method="init" destroy-method="destory"/>   
      
      
       <!-- 使用 类构造器方法        实例化 PersonService   
        <bean id="personService1" class="com.milo.services.impl.PersonServiceBean" scope="prototype"/>
      
       使用 静态工厂方法        实例化PersonService 
       <bean id="personService2" class="com.milo.services.impl.PersonServiceBeanFactory" factory-method="createPersonServiceBean"/>
      
       使用 实例化工厂方法   实例化PersonService 
       <bean id="personServiceFactory" class="com.milo.services.impl.PersonServiceBeanFactory"/>
       <bean id="personService3" factory-bean="personServiceFactory" factory-method="createPersonServiceBean2"/>
  -->
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值