Spring接口注入示例 [英] Spring interface injection example

查看:181
本文介绍了Spring接口注入示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,没有人能够在Spring Framework中提供正确的接口注入示例。 Martin Fowler的文章不是为了凡人,其他一切只是以非常令人困惑的方式定位。我已经浏览过三篇文章,其中人们要么告诉Spring不直接支持界面注入(因为我不确切地知道我将如何描述setter和构造函数注入)或者我会在我的讨论中讨论它其他线程或者下面会有一些评论说这是错误的例子。我没有要求解释,例如我BEG。

No one so far was capable of providing a working correct example of interface injection in Spring Framework. Martin Fowler article is not for mortals, everything else just words positioned in a very confusing way. I have surfed over THIRTY articles, where people either tell "Spring doesnt directly supports for interface injection"("and because I don't know exactly how I will only describe setter and constructor injections") or either "I will discuss it in my other threads" or either there will be few comments below saying that it is wrong example. I don't ask for explanation, I BEG for example.

有三种类型的注入:构造函数,Setter和接口。 Spring不直接支持最新版本(正如我观察人们所说)。那怎么做呢?

谢谢,

推荐答案

根据春季DI的变种


DI存在两个主要变体,基于构造函数的依赖注入和基于Setter的依赖注入。

DI exists in two major variants, Constructor-based dependency injection and Setter-based dependency injection.

另见 Spring中没有实现接口注入明确说明它。

所以只有两个DI的变体。因此,如果文档没有说明接口注入,那么很明显它不存在。那些认为界面注入是通过在接口中提供setter方法来完成的人回答我:

So there are only two variants of of DI. So if documentation says nothing about interface injection, its clear that its not there. Those who believe that interface injection is done by providing setter method in interface answer me:


  1. 为什么spring ref doc还提到了接口注入? / li>
  2. 为什么不能通过提供setter方法 NOT 作为setter注入本身来进行接口注入。为什么在引入界面不影响任何东西时创建特殊术语,我的意思是它仍然以相同的方式配置。如果它们不同,那么如何通过查看配置找到它。不应该透明,在配置中没有看到实际配置的类实现某个接口的impl?

  3. 就像使用实例工厂方法实例化使用实例化一个静态工厂方法,一些bean属性应该澄清接口注入?

  1. Why spring ref doc left mention of interface injection?
  2. Why cann't interface injection via providing setter method NOT considered as setter injection itself. Why create special term for that when introduction of interface doesn't affect anything, I mean its still configured the same way. If they were different then how can one find it via seeing the config. Shouldn't it be transparent that in config and not seeing the impl that actually configured class implements some interface ?
  3. Just like Instantiation using an instance factory method and Instantiation using an static factory method, some bean attributes should clarify the interface injection?

这篇关于Spring接口注入示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆