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、接口注入(不常用)
网上说会增加耦合 不建议使用 我也没有用过 暂且先不谈 会了的话在更新^_^
?
?
?