Pro Spring2.5 Over view ---- Ioc DI

1. Spring 包的组成:

 

1> spring-aop.jar This JAR contains all the classes you need to use Spring’s AOP features within your application. You also need to include this JAR in your application if you plan to use other features in Spring that use AOP, such as declarative transaction management.

 

2> spring-beans.jar: This archive contains all of Spring’s dependency injection. It contains the bean factories and supporting classes. In most cases, you will need to add spring-context.jar, which contains code needed to build the application context.

 

3> spring-context.jar: This JAR contains code needed to build the Spring application context; it packages the main ApplicationConext interface and its implementations together with code for instrumentation, JNDI,scheduling, themes, and validation.

 

4> spring-context-support.jar: This package contains utility Spring code—this means caching, instrumentation, e-mail and scheduling support, and the very interesting scripting languages support.

 

5> spring-core.jar: This contains the core files of the Spring Framework: it deals with annotations, enumerations, task execution, resource loading, and other utilities and exceptions you may find useful even outside the context of the Spring Framework.

 

6> spring-jdbc.jar: This package contains code for the JDBC support classes, namely the JdbcTemplate and JdbcDaoSupport classes

 

7> spring-jms.jar: This JAR contains code for JMS;

 

8> spring-orm.jar: This archive contains the files needed for object-relational mapping (ORM) tools. Including this package on your classpath will give you Spring support for Hibernate 3, iBATIS, JDO, JPA, and TopLink.

 

9> spring-test.jar: This package contains support code to write unit and integration tests using the Spring Framework. It supports the JUnit 3, JUnit 4, and TestNG testing frameworks. In addition, you can use classes from the org.springframework.mock package, which represent mock implementations of JNDI and web classes.

 

10> spring-tx.jar: This one contains support for core data access exceptions and transaction technologies. These two areas are closely bound together, because the transactions generally work with some data access code.

 

2. Ico 介绍:

 

Ioc 是 Inversion of control 简写。 DI 是 Dependency Injection 的缩写。还有事 dependency lookup 依赖查找。 DI 和 DL是IOC 的两种形式。DL和现有代码的是耦合的, DI 和代码是完全解耦的。

 

DI 分为构造器(Constructor)DI 和setter DI.

 

beanFactory 是DI 的核心容器。bean是容器管理的组件(Component)。

 

一般的系统和spring交互都是通过beanfactory接口来完成的。

 

对于所有的beanfactory类来说,都要实现BeanDefinitionRegistry接口。

 

你可以读取beanDefinition 数据从配置文件中。

 

创建beanfactory的方式之一:


XmlBeanFactory bf = new XmlBeanFactory(
new ClassPathResource("/META-INF/spring/beanfactorydemo1-context.xml"));

 

 

构造器的形式的注入的xml配置例子:

 

<bean id="encyclopedia"
class="com.apress.prospring2.ch03.di.ConfigurableEncyclopedia">
<constructor-arg>
<util:map>
<entry key="AgeOfUniverse" value="13700000000"/>
<entry key="ConstantOfLife" value="326190476"/>
</util:map>
</constructor-arg>

</bean>
<bean id="oracle" class="com.apress.prospring2.ch03.di.BookwormOracle">
<property name="encyclopedia" ref="encyclopedia"/>
</bean>

 

 

设置注入的类型的例子

 

<bean id="constructorConfusion"
class="com.apress.prospring2.ch03.beanfactory.ConstructorConfusionDemo">
<constructor-arg value="1" type="int" />
</bean>

 

配置属性值的例子:

 

<bean id="injectSimpleDemo"
class="com.apress.prospring2.ch03.beanfactory.InjectSimpleDemo">
<property name="name" value="John Smith"/>
<property name="age" value="35"/>
<property name="height" value="1.79"/>
<property name="isProgrammer" value="true"/>
<property name="ageInSeconds" value="1103760000"/>

</bean>

 

用p 命名空间(namespace)的方式设置属性

 

<bean id="injectSimpleDemo"
class="com.apress.prospring2.ch03.beanfactory.InjectSimpleDemo"
p:age="35" p:ageInSeconds="1103760000"
p:height="1.79" p:isProgrammer="false"
/>

 

用p命名空间设置bean的引用 p:name-ref ="ref_name"

 

<bean id="oracle" class="com.apress.prospring2.ch03.di.BookwormOracle"
p:encyclopedia-ref ="knowitall" />

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值