spring-scope.xml 879 B

1234567891011121314151617
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  5. <!--
  6. scope:设置bean的作用域
  7. scope = "singleton | prototype"
  8. singleton:单例,表示获取该bean所对应的对象都是同一个
  9. prototype:多例,表示获取该bean所对应的对象都不是同一个
  10. 单例情况是使用最多的,默认也是单例,只有在某些特殊情况下才会使用多例
  11. -->
  12. <bean id="student" class="com.cdxw.spring.pojo.Student" scope="singleton">
  13. <property name="sid" value="1001"></property>
  14. <property name="sname" value="张三"></property>
  15. </bean>
  16. </beans>