首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

spring流入的几种方式

2012-06-26 
spring注入的几种方式1、setter方式(最常用)? 就是在bean中的属性必须有setter方法 然后在xml在配置2、构造

spring注入的几种方式

1、setter方式(最常用)

? 就是在bean中的属性必须有setter方法 然后在xml在配置

2、构造方法(不常用)

参考官方api的例子:

?

?b.按参数索引传给构造方法注入(索引从0开始)[ Constructor Argument Index?]

?

?

?

Some examples

?

public class ExampleBean {    // a private constructor    private ExampleBean(...) {      ...    }        // a static factory method; the arguments to this method can be    // considered the dependencies of the bean that is returned,    // regardless of how those arguments are actually used.    public static ExampleBean createInstance (            AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {        ExampleBean eb = new ExampleBean (...);        // some other operations...        return eb;    }}
?

?

?

3、接口注入(不常用)

网上说会增加耦合 不建议使用 我也没有用过 暂且先不谈 会了的话在更新^_^

?

?

?

热点排行