依赖注入的3种实现方式

 依赖注入的意义:让组件依赖于抽象,当组件要与其他实际对象发生依赖关系时,通过抽象来注入以来的实际对象。

3种实现方式:接口注入、Set注入、构造注入

接口注入就不要学了,因为根本是用不到的,呵呵……

Set注入:

详情请看:http://blog.csdn.net/caoxu1987728/archive/2008/05/21/2467603.aspx

注:基本上是相同的。不同点:1,原是建立在tomcat Project上,而在建立web Project时有一点不同:config.xml在project目录下而与WebRoot同目录(非与Web-INF同目录);2,现日志有没有没什么关系(可能原也没关系,但过于追求书本了)。

结果如下:

2008-07-26 21:39:44,679 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from file [C:/Documents and Settings/Administrator/workspace/myApp/config.xml]>
2008-07-26 21:39:44,772 INFO [org.springframework.context.support.FileSystemXmlApplicationContext] - <Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12893404]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [helloWorld]; root of BeanFactory hierarchy>
2008-07-26 21:39:44,788 INFO [org.springframework.context.support.FileSystemXmlApplicationContext] - <1 beans defined in application context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=12893404]>
2008-07-26 21:39:44,788 INFO [org.springframework.core.CollectionFactory] - <JDK 1.4+ collections available>
2008-07-26 21:39:44,788 INFO [org.springframework.context.support.FileSystemXmlApplicationContext] - <Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@867e89]>
2008-07-26 21:39:44,804 INFO [org.springframework.context.support.FileSystemXmlApplicationContext] - <Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@276af2]>
2008-07-26 21:39:44,804 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [helloWorld]; root of BeanFactory hierarchy]>
HelloWorld

构造注入:

详细点击:http://blog.csdn.net/caoxu1987728/archive/2008/05/22/2469064.aspx

结果同上。

对……滴

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值