Spring4 IOC注解开发和xml开发对比

1 创建web项目

2 引入jar包(Spring4的版本需要多引入一个aop的包

Spring4 IOC注解开发和xml开发对比

3 编写applicationContext.xml配置文件

    注解  ======================

a.引入的是beans的schema

b.只需要配置扫描那些包下的类即可

<context:component-scan base-package="com.spring"></context:component-scan> 

     xml  ======================

a.引入的是beans+context的schema

b.不需要配置任何扫描

 

4. IOC和DI

注解 ======================= 

在类中进行配置IOC的DI

Spring4 IOC注解开发和xml开发对比

xml  =======================

在配置文件中配置IOC和DI

Spring4 IOC注解开发和xml开发对比 5 init-method和destory-method的配置(单例模式且工厂销毁才会执行destory方法)

xml  =======================

Spring4 IOC注解开发和xml开发对比

注解 =======================

Spring4 IOC注解开发和xml开发对比

6 作用范围的配置

xml  =======================

Spring4 IOC注解开发和xml开发对比

注解  ======================= 

Spring4 IOC注解开发和xml开发对比