- 浏览: 428612 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (211)
- 思考》感想 (11)
- 数据库操作 譬如Oracle大叔 (7)
- java,咱们有缘吗 (16)
- delphi,你还好吗 (2)
- SSH,哥三儿好 (31)
- 问题!问题?问题!? (9)
- WITH WORK (1)
- 算法与模式 莫事^_^ (10)
- JSP,可以叫你P兄么 (2)
- 啊,咋科斯╮(╯▽╰)╭ (6)
- 巨人肩上的小石子 (2)
- flash她妹flex (38)
- 项目管理 (10)
- 奥特曼,你弟Android来了 (4)
- 麻辣儿gis (0)
- maven 嘛味儿 (3)
- ws 哇塞 webservice (5)
- Oh,no!!!,NoSql (1)
- QQ他哥也是个企鹅,Linux (6)
- 姓i还是姓my 你都叫batis ibatis (3)
- 我喜欢夏天(春天旁边的那个季节)Springside (1)
- 测试! 测就测吧,没有喝(⊙o⊙) (3)
- 是晕+_+ 是浮云 还是云计算 (4)
- ExtJS 你是flex他哥还是他妹 (10)
- svg 你丫的资料真少 (3)
- 叫屁屁还是叫加加 ⊙﹏⊙ c++ (5)
- 鸟,还是只百灵鸟 BIRT (1)
- 权限管理 有权真好 是吧-_-! (1)
- SSH (2)
- 哥三儿好 (2)
- nginx (1)
- Oh (1)
- no!!! (1)
- NoSql (1)
最新评论
-
mong619226543:
谢谢
No identifier specified for entity -
akka_li:
没看懂啥意思!什么原因导致java.net.SocketExc ...
java.net.SocketException: Connection reset 问题解决方法 -
west_jing:
1L正解,<mvc:annotation-dri ...
<mvc:default-servlet-handler/> 导致 Controller失效 -
u010954806:
tgfhfdhdf
Spring Security 国际化文件 messages_zh_CN.properties 中文解释 -
yenshen:
我也碰到这个问题了,找了一大圈,最终问题解决了:<pre ...
<mvc:default-servlet-handler/> 导致 Controller失效
* AOP操作可与通过注解和xml的方式实现;
* 有个问题,如果高手看到了可以考虑下:采用注解实现,用后置通知的时候,如果后置通知方法名叫after()的话,则先会打印最终通知,后打印后置通知!!!,用xml没有这个问题,很怪啊????
* 采用注解方式,切面也必须交给sping管理;
*配置实例
application.xml------->
注解实现的MyInterceptorAnnotation------->
xml实现的MyInterceptorXML------->
结果------->
这是前置通知
进入环绕通知
这是update方法
这是后置通知
这是最终通知
退出环绕通知
* 有个问题,如果高手看到了可以考虑下:采用注解实现,用后置通知的时候,如果后置通知方法名叫after()的话,则先会打印最终通知,后打印后置通知!!!,用xml没有这个问题,很怪啊????
* 采用注解方式,切面也必须交给sping管理;
*配置实例
application.xml------->
<?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="productService" class="com.xx.dao.impl.ProductServiceBean"></bean> <!-- 注解方式 --> <!-- <aop:aspectj-autoproxy/> <bean id="myInterceptor" class="com.xx.aspect.MyInterceptorAnnotation"></bean> --> <!-- xml配置方式 --> <bean id="myInterceptor" class="com.xx.aspect.MyInterceptorXML"></bean> <aop:config > <aop:aspect ref="myInterceptor"> <aop:pointcut id="myAop" expression="execution(java.lang.String com.xx.dao.impl.ProductServiceBean.*(..))"/> <aop:before pointcut-ref="myAop" method="before"/> <aop:after-throwing pointcut-ref="myAop" method="exception"/> <aop:after-returning pointcut-ref="myAop" method="afterReturn"/> <aop:after pointcut-ref="myAop" method="after"/> <aop:around pointcut-ref="myAop" method="around"/> </aop:aspect> </aop:config> </beans>
注解实现的MyInterceptorAnnotation------->
package com.xx.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; /** * 切面类(annotation配置实现) * @author user * */ @Aspect public class MyInterceptorAnnotation { @Pointcut("execution(* com.xx.dao.impl.ProductServiceBean.*(..))") private void anyMethod(){}//声明一个切入点 @Before("anyMethod()") public void before(){ System.out.println("这是前置通知"); } @AfterReturning("anyMethod()") public void afterReturn(){ System.out.println("这是后置通知"); } @After("anyMethod()") public void after1(){ //如果改为after()的话,则先会打印最终通知,后打印后置通知!!!,用xml没有这个问题,很怪啊。 System.out.println("这是最终通知"); } @AfterThrowing("anyMethod()") public void exception(){ System.out.println("这是例外通知"); } @Around("anyMethod()") public Object around(ProceedingJoinPoint pjp) throws Throwable{ System.out.println("进入环绕通知"); Object result = pjp.proceed(); System.out.println("退出环绕通知"); return result; } }
xml实现的MyInterceptorXML------->
package com.xx.aspect; import org.aspectj.lang.ProceedingJoinPoint; /** * 切面类(XML配置实现) * @author user * */ public class MyInterceptorXML { public void before(){ System.out.println("这是前置通知"); } public void afterReturn(){ System.out.println("这是后置通知"); } public void exception(){ System.out.println("这是例外通知"); } public void after(){ System.out.println("这是最终通知"); } //环绕通知时固定写法 public Object around(ProceedingJoinPoint pjp) throws Throwable{ System.out.println("进入环绕通知"); Object result = pjp.proceed(); System.out.println("退出环绕通知"); return result; } }
结果------->
这是前置通知
进入环绕通知
这是update方法
这是后置通知
这是最终通知
退出环绕通知
发表评论
-
Spring Security 国际化文件 messages_zh_CN.properties 中文解释
2011-05-04 17:08 7031Spring Security 国际化文件 messages_ ... -
两个Spring Security问题
2011-05-04 17:06 2059两个Spring Security问题 ---------》 ... -
一个spring security 配置列子
2011-05-03 16:48 1220<?xml version="1.0" ... -
spring security与数据库交互实现简单例子
2011-04-19 16:34 1633spring security与数据库交互实现简单例子 最近 ... -
用struts2 验证用户登录demo
2011-01-28 15:38 2154用struts2 验证用户登录de ... -
Struts2.1.8 执行顺序
2011-01-28 15:18 865public class LoginAction extend ... -
Struts2令人纠结的一个问题
2011-01-27 09:47 970我用Struts2加入自定义的library如下图,就报错, ... -
一份spring配置文件
2011-01-13 14:05 940<?xml version="1.0" ... -
Hibernate关系映射总结
2010-10-18 10:35 1243其实这些东东完全可以参考帮助文档;这里只是总结下。 》》》一对 ... -
No identifier specified for entity:XX.xx
2010-10-12 17:25 1646No identifier specified for ent ... -
Annotation对Hibernate中联合主键定义
2010-10-11 13:28 2202public class User { private in ... -
@MappedSuperclass的用法
2010-10-11 10:21 12588@MappedSuperclass的用法 用在实体的继承过程 ... -
公共dao的结构
2010-09-29 16:17 1337-----------》公共dao的结构 -----共用接口 ... -
No identifier specified for entity
2010-09-29 16:07 11960org.hibernate.AnnotationExcepti ... -
SSJ配置模板
2009-09-14 09:06 859web.xml-----> <?xml versi ... -
一个简单的ssh配置模板
2009-09-12 17:08 1683web.xml------> <?xml vers ... -
Struts----学习笔记 用form提交和sturts提交
2009-09-12 17:02 1193struts是这么配置的 <action path= ... -
Spring学习笔记------Spring和Hibernate的整合配置
2009-09-12 09:15 1390Spring和Hibernate整合配置有两种方式: 方 ... -
Hibernate学习笔记1--------一个简单的应用
2009-08-30 08:26 994工具类---------> /** *用单例模式 ... -
Hibernate学习笔记2--------------------一对多、多对一简单配置
2009-08-30 08:40 972一的一端------------------------> ...
相关推荐
NULL 博文链接:https://microjava.iteye.com/blog/525796
自己学习spring课程的笔记。笔记都是根据尚硅谷的课程(spring ioc,spring aop,spring mvc,spring boot等)写的。 主要内容:spring ioc,spring aop,spring mvc,spring boot
Spring学习笔记,主要包括核心技术IOC和AOP
Spring Aop 学习笔记
NULL 博文链接:https://linres.iteye.com/blog/281221
SpringAOP学习笔记以及四个可运行的Demo,涵盖经典代理模式、基于注解、基于xml配置这3方面的Demo
该压缩包包含--学习笔记(05):轻松搞定Spring全家桶(初识篇)-面向切片编程AOP:--系列博客中新需要的三个jar包。包括spring-aspects-5.2.7.RELEASE.jar和spring-aop-5.2.7.RELEASE.jar和...
springboot学习笔记 spring基础 Spring概述 Spring的简史 xml配置 注解配置 java配置 Spring概述 Spring的模块 核心容器CoreContainer Spring-Core Spring-Beans ...
NULL 博文链接:https://coolszy.iteye.com/blog/540465
NULL 博文链接:https://coolszy.iteye.com/blog/541997
在“Java Spring学习笔记”中,你将找到对Spring框架的全面介绍,包括IoC(控制反转)和DI(依赖注入)原理、AOP(面向切面编程)、Spring MVC、Spring Boot等核心内容。每个主题都结合了理论知识和实际示例,帮助你...
记录自己关于Spring的学习笔记还有Demo ,笔记均在Demo注释部分,后续会整理成MarkDown格式的文件发布在博客上。 如果觉得对您有帮助,您的Start就是对我最大的认同。 欢迎互相学习交流,如果项目中有问题的部分可以...
NULL 博文链接:https://coolszy.iteye.com/blog/540457
SpringCloud笔记 1、前言 1.1、回顾 回顾之前的知识 JavaSE 数据库 前端 Servlet Http Mybatis Spring SpringMVC SpringBoot Dubbo、Zookeeper、分布式基础 Maven、Git Ajax、Json ... 串一下自己会的东西 数据库 ...
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ...
Spring学习笔记Spring spring的配置 IOC 依赖注入 基于Xml的注入 基于注释的注入 Spring的自动注入和属性自动注入 AOP 静态代理 动态代理 使用spring实现AOP 基于Annotation实现AOP 基于XML实现AOP ...
spring从HelloWorld到ioc,aop,对JDBC,hibernate,struts1,struts2的支持笔记
第八课:Spring AOP配置选项 21 一、 AOP配置annotation方式 21 (一) 搭建annotation开发环境 21 (二) aspectJ类库 22 (三) AOP的annotation实例 22 (四) AspectJ的专业术语 23 (五) 织入点语法 23 (六) Advice 24 ...
《Spring技术内幕》学习笔记1——IoC容器体系结构 《Spring技术内幕》学习笔记2——IoC定位Bean定义资源 《Spring技术内幕》学习笔记3——IoC容器载入Bean定义资源文件 ...《Spring技术内幕》学习笔记7——AOP基础