---
title: "重温spring（一）"
author: "jps2004cz"
date: "2009-03-31T23:32:30Z"
tags: []
slug: "spring"
draft: false
lastmod: "2009-03-31T23:34:20Z"
id: 358671
url: "https://jps2004cz.iteye.com/blog/358671"
---

spring bean四种装配：
1.byName
2.byType
3.constructor
4.atuodetcet （先根据constructor，在根据byType装配）
四种装配各有利弊，开发中采取手工加自动的方式更为妥当些。

bean的范围：（scope）
1.singleton
2.prototype
3.request
4.session
5.global-session

bean的创建一般采用factory-method
bean的初始化和销毁init-method，destory-method

bean的继承：通过parent指定
1.父子类，声明abstract作为基类，其他bean通过parent引用，简化配置。
2.信息共享，多个属性同时被多个bean所有，这时可以定义一个单独的abstract的bean供其他bean引用。

spring DI 3中方式：
1.constructor
2.setter
3.method
方法注入通过replaced-method，lookup-mothed替换或代替已有方法。

spring的脚本化bean 
首先设置spring的xml定义，引入spring-lang-2.0.xsd
<lang:jruby id="name" refresh-check-delay="5000"
    script-source="文件位置"
    script-interfaces="实现接口"
</lang:jruby>
refresh-check-delay属性指定脚本刷新频率。
这也可以作为混合编程的一种集成方式。
<lang:jruby id="name"  script-interfaces="实现接口">
   <lang:inline-script>
     <!CDATA]>
   </lang:inline-script> 
</lang:jruby>
这种方式使配置文件冗余加长，不建议使用。