Spring框架的整理

一:核心

    (1):IOC  控制反转

    (2):AOP 面向切面

二:优点

     (1):方便解耦,简化开发(把对象的创建和依赖关系的维护交给Spring)

     (2):对AOP的支持,实现拦截,监控,事务管理等功能

     (3):Junit4的支持(测试类  @RunWith(SpringJUnit4ClassRunner.class)    @ContextConfiguration("classpath:applicationContext.xml"))

     (4):支持各种框架的整合

     (5):对部分难用的API做了封装,如JDBC,JavaMail,远程调用等

三:关于applicationContext

      (1):ClassPathXmlApplicationContext  加载类路径下的Spring的配置文件

      (2):FileSystemXMLApplicationContext       加载本地磁盘下的Spring的配置文件

四:Beanfactory和ApplicationContext的区别

                    Beanfactory在getBean的时候才会生成类的实例

                    ApplicationContext在加载ApplicationContext.xml时就创建

五:Bean 的属性

           id(唯一 ,不能有特殊符号)

          name(可以有特殊符号,整合Struts框架的时候会用到)

          class

         scope(默认情况下是单例模式singleton    prototype是多利)

         生命周期的方法init和dsetory

六:DI注入

            (1):构造方法注入:constructor-arg     name    value    当为对象用ref

            (2):set方法注入:property      name    value    当为对象用ref

           (3):名称空间P的属性注入方式

                         (一):引入P名称空间(schema约束)

                        (二):使用p名称空间               格式:普通属性   p:属性名=" "   对象类型属性   p:属性-ref=" "

            (4):SPEL方式的属性注入        

                                      语法         #{SPEL }

            (5):复杂类型注入

                                   例如:数组;List集合;map集合;properties的注入等

         <property name="strings">
			<array>
				<value>aa</value>
				<value>bb</value>
			</array>
		</property>
		<property name="list">
			<list>
				<value>中国</value>
				<value>大地</value>
			</list>
		</property>
		<property name="set">
			<set>
				<value>东邪</value>
				<value>西毒</value>
				<value>南帝</value>
				<value>北丐</value>
			</set>
		</property>
		<property name="map">
		    <map >
		       <entry key="张翠山" value="1"></entry>
		       <entry key="张无忌" value="2"></entry>
		    </map>				
		</property>		
         <!-- 给属性集合文件赋值 -->
        <property name="properties">
             <props >
                 <prop key="杨过">郭襄</prop>
                 <prop key="小龙女">绿鄂</prop>
             </props>    
        </property>


七:关于多个Spring配置文件的解决方案


                      (1): ClassPathXmlApplicationContext(“applicationContext1.xml ”,“ applicationContext2.xml ”)

                      (2):或者采用包含的方式<import resource="配文件"></import>

八:Spring在各个层的注解

                      在类上的注解:@component(value=" ")        是在xml中注册对象时所对应的id

                      web层:@controller

                      service层:@service

                      持久层:@Repository

                      属性注入的注解(可以不用提供set方法)

                      @Autowired

                     @Qualifer(“属性名”)

                      关于生命周期配置的注解

                      @postConstruct     相当于init-method

                      @preDestory          相当于destory-method

九:AOP面向切面的编程(通过预编译方式和运行期动态代理实现程序功能的统一维护)

                    在不修改源码的情况下,对程序进行增强

                    AOP进行权限校验,日志,记录,性能等的监控,事务的控制

                     底层采用代理机制

                    (一):JDK动态代理,针对实现了接口的类进行代理

                    (二):Cglib的动态代理,针对没有实现接口的类产生代理,应用的是底层的字节码增强的技术,生成当前类的子类对象

十:AOP的相关术语

                    连接点:目标类中的所有方法(Spring只支持方法类型的连接点)

                    切入点:需要被增强的方法

                   通知类:公共模块的能力

                   目标类:服务层的类

                   织入:通知应用到目标创建代理类的过程,是一个虚拟的过程

                  代理类:整合目标类和通知类

                  切面:通知和切入点关联就叫切面

                  备注:通知的类型(前置,后置和环绕)和切入点的表达式 execution()

十一:AspectJ的AOP注解

                    @After              @AfterReturning                                 @Around

                    关于它的xml配置为


          <!-- AOP编程: aspectj的方式-->
         <aop:config>
	<!-- aspectj的单独节点 :关联到aspectj的通知-->
	    <aop:aspect ref="myAspect">
	<!-- 定义切入点 -->
	
	      <aop:pointcut expression="execution(* com.qf.service.*.*(..))" id="mpPoint"/>
	<!-- aspectj的通知 
			method=""写的是自定义的方法名称
			-->
		<!-- 	<aop:before method="befor" pointcut-ref="mpPoint"/> -->		
			<aop:after-returning method="after" returning="res" pointcut-ref="mpPoint"/>
			<!-- <aop:around method="round" pointcut-ref="mpPoint"/> -->			
	</aop:aspect>	
	     </aop:config>

若有错误的地方或不足的地方,请多多指教,谢谢!!!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值