依赖注入的意义:让组件依赖于抽象,当组件要与其他实际对象发生依赖关系时,通过抽象来注入以来的实际对象。
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;
结果同上。
对……滴