spring复盘

得到对象:

  1.     Students s = new Student()
    
  2.     Class.forName(“”).newInstance();
    
  3.     工厂方法(在里面定义一个静态方法)模式称为:创建模式
    
  4.     sping配置文件可以实现
    

(MVC框架)
Struts JSF webwork shale(JSF) sping tasptny
Sping
IOC AOP
Sping 框架里面 有IOC AOP
Sping 也推出了MVC
还有 Email管理。 还有自己的DAO
Web况架 MVC
Java 核心在于 思想

在java分三层
表现层 业务逻辑层 持久层
Struts EJB/WEBService/RMI hibernate
通过这些还可以使用sping做为轻量级的框架
EJB和服务器非常紧密
RMI :Remote M:方法 I:调用invoke
选程方法调用
面像接口编程
接口定义好后不能实列化必须定义一个实现类
配置文件。

通过注入(调用set方法或构造器)

ClassPathResource(“hello.xml”);
这是在.classpath下去找hello.xml"放到src下面
InputStream fin = new FileInputStream(“E://hello.xml");
这是在文件下去找
ClassPathXmlApplicationContext—Loads a context definition from an XML file located in the class path, treating context definition files as class path resources.
■ FileSystemXmlApplicationContext—Loads a context definition from an XML file in the filesystem.
■ XmlWebApplicationContext—Loads context definitions from an XML file contained within a web application.
Getbean()使用的单子模式。
第一次会new一下第二次会直接去找。


Sping…


默认会单子模式
如果不想让他给单子模式给我:则

< bean id = “greetingService”
class = “com.softeem.sping.GreetingServiceImpl” init-method = “intialization” destroy-method = “depintialization” >
初始化 init-method = “intialization” 调用这个方法
当消失时调用 destroy-method = “depintialization” 方法

构造器传值

代理方法处理日志
每一个代理类 要给谁代理。。就把那个需要代理的传过来
通知
在调用之前通知。在调用之后通知
核心 配置 全部东西 都可以通过sping
AOP 概念
Spring进行面向切面编程(AOP)
切入点:找到在哪里就是查找(里面定义的查找)。把通知切进去!
面像切面
Stping:拦截器
Spint:通知 :前通知(Beforadvice)。后通知(AfterreturningAdvice):异常通知(Thorwsadvice) 环扰通知(MetgidUbterceotir)
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
System.out.println(“before…”);
}
参数3 被代理类
参数1:(方法)反射 Methor.invoke()反射机制可以实现方法
参数2参数集合
Joinpoint(连接点)
Pointcut(切入点)
1:我的通知是什么。2:告诉我的Sping告诉在哪个点怎么切入
在代理类做拦截器
通知器/切面封装器(Advisor)
DefaultPonincutAdvisor默认的切面封装
XML

为什么要做AOP
AOP核心是什么??
那到底什么叫切面?
每一个方法都会做一个事情。这样会大量重复
解决。:
拦截器名是用来配置切面的。

注入:set 和构造器AOC
Sping的配置:
第一:配置实现类。
第二:配置切点
第三:配置通知
第四:把切点和通知配置封装到切面去
第五:把切面封装到代理类的(拦截器)去

<?xml version="1.0" encoding="UTF-8"?>
                 <value>com.softeem.bs.service.GreetingService</value>
          </property>
         
          <property name="interceptorNames"><!-- 拦截器 -->
                 <list>
                        <value>advisor</value>
                 </list>
          </property>
          <property name="target"> <!-- 代理哪个类(实现类) -->
                 <ref local="greetingServiceTarget" />
          </property>
   </bean>


   <bean id="advisor" class="org.springframework.aop.support.DefaultPointcutAdvisor"><!-- 把切点和通知配置到切面里面去 -->
          <property name="advice">
                 <ref local="advice" />
          </property>
          <property name="pointcut">
                 <ref local="pointcut" />
          </property>
   </bean>
  
  

   <bean id="pointcut"
          class="org.springframework.aop.support.NameMatchMethodPointcut"><!-- 切入 --><!-- 根据名称来切入 -->
          <property name="mappedNames">
                 <list>
                        <value>say*</value>
                        <value>find*</value>
                 </list>
          </property>
   </bean>

   <bean id="advice" class="com.softeem.bs.service.WelcomeAdvice" /><!-- 通知-->

   <bean id="greetingServiceTarget"
          class="com.softeem.bs.service.GreetingServiceImpl"><!-- 实现类 -->
          <property name="greeting">
                 <value>hello world...</value>
          </property>

   </bean>

• Joinpoint( 连接点) : Point during the execution of a program, such as a method invocation or a particular exception being thrown.
org.springframework.aop.Pointcut interface.
• Pointcut( 切入点):在任何一个 AOP 框架中,一个必要的部分就是如何定义及描述连接点与切入点。在Spring 的 AOP 实现中,由于只实现了针对方法调用的拦截及通知,在此我们只关心方法连接点。Spring 中的跟其它 AOP 框架一样,对于方法连接点主要是观察方法执行前、方法执行正常返回后、方法执行抛出异常时以及方法执行过程中这几个方面。

• 切面的定义包括两个方面,一个是通知,一个是切点;
• 在Spring 中,给我们提供预定义的 PointcutAdvisor 实现,我们直接在应用程序中使用他即可,下面分别看看这些切入点封装实现。
• DefaultPointcutAdvisor 默认的切面封装
• NameMatchMethodPointcutAdvisor 方法匹配切入点切面封装
• RegexpMethodPointcutAdvisor 正则表达式切入点切面封装
• AspectJExpressionPointcutAdvisor AspectJ 表达式切入点切面封装

Advice(通知):
前通知 before advice
是指在连接点之前,先执行通知中的代码。
后通知 after advice
是指在连接点执行后,再执行通知中的代码。
环绕通知 around advice
Throws advice
Throws advice is invoked after the return of the join point if the join point threw an exception.
Introduction advice

Aspect( 方面): A modularization of a concern for which the implementation might otherwise cut a cross multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications, Aspects are implemented using Spring as Advisors or interceptors(拦截器).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值