【Spring实战4】01---初接触

学习线路图:

1、Spring框架的核心知识

2、Spring构建Web应用程序

3、后端使用Spring

4、Spring与其他应用和服务进行集成

在学习前做了一些功课,其中都强调了Spring容器、依赖注入(或者说控制反转)和面向切面编程AOP,对于学习Spring来说这部分内容很重要。

基础部分讲解了spring核心特性:依赖注入 和 面向切面编程

依赖注入的最大收益---松耦合:

第一章主要讲述了一些Spring在开发中的应用实例,Spring通过面向POJO编程、DI、切面和模板技术来简化java开发中的复杂性

如:

在Car类中run方法执行前后,为RUN方法增加before以及after方法描述

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-xsd">
        <bean id="car" class="nh.spring.ioc.beans.Car">
            <property name="brand" value="Ca11"/>
            <property name="color" value="blue"/>
        </bean>

        <bean id="runCar" class="nh.spring.ioc.beans.RunCar">
            <constructor-arg value="#{T(System).out}"/>
        </bean>

        <aop:config>
            <aop:aspect ref="runCar">
                <aop:pointcut id="show" expression="execution(* show())"/>
                <aop:before method="carBeforeRun" pointcut-ref="show"/>
                <aop:after method="carAfterRun" pointcut-ref="show"/>
            </aop:aspect>
        </aop:config>
</beans>
原文地址:https://www.cnblogs.com/hylinux/p/6022216.html