- 浏览: 799876 次
- 性别:
- 来自: 西安
文章分类
- 全部博客 (307)
- struts (8)
- hibernate (3)
- spring (32)
- opensourceproject (12)
- javaScript (9)
- primeton EOS (2)
- journey of heart (10)
- Design pattern (6)
- ejb (17)
- point (37)
- Linux&Unix (22)
- ibatis (10)
- AJAX (6)
- DB (26)
- Protocol (6)
- chart (4)
- web server (11)
- webservice (7)
- integration (3)
- tuxedo (5)
- ext (4)
- android (1)
- c/c++ (12)
- JVM (1)
- paginationFrame (2)
- code (2)
- report (1)
- High-performance web (1)
- svn (1)
- JQuery (1)
- workDaily (2)
- cloud (16)
- Python (8)
- English (2)
- shell (5)
- googleCode (1)
- nio (1)
- hyper-v (1)
- debug (3)
- vbs (2)
- openstack (3)
- K8S (1)
- Mesos (0)
- Spark (0)
- Marathon (0)
最新评论
-
钱图大展:
chao2751021 写道lib包哪里去下载,找不到
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
钱图大展:
无法下载
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
fm395728572:
shell脚本中用到了环境变量,但是获取不到,例如脚本中有一句 ...
ganymed-ssh2 for Java -
liuhanjiang:
我qq147229234
大型网站用户行为记录的一个实现--基于clickStream(第一部分) -
liuhanjiang:
博主 我利用您提供的方法实现博文中介绍的clickstream ...
大型网站用户行为记录的一个实现--基于clickStream(第一部分)
上面我们是使用注解的方式实现spring AOP的,下面我们使用Spring的配置文件实现AOP
步骤:
1.首先写切面类,不在需要任何 注解 了
package cn.com.xinli.service; import org.aspectj.lang.ProceedingJoinPoint; /** * 切面 * */ public class MyInterceptor { public void doAccessCheck() { System.out.println("前置通知"); } public void doAfterReturning() { System.out.println("后置通知"); } public void doAfter() { System.out.println("最终通知"); } public void doAfterThrowing() { System.out.println("例外通知"); } public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { System.out.println("进入方法"); Object result = pjp.proceed(); System.out.println("退出方法"); return result; } }
(2) 在beans.xml 中配置 切面,定义业务bean
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <aop:aspectj-autoproxy proxy-target-class="true"/> <!--切面和业务bean都需要交给容器管理--> <bean id="myInterceptor" class="cn.com.xinli.service.MyInterceptor"></bean> <bean id="personService" class="cn.com.xinli.service.impl.PersionServiceBean"></bean> <aop:config> <!-- 定义一个切面 --> <aop:aspect id="asp" ref="myInterceptor"> <!-- 定义切入点,定义拦截表达式,前置通知,后置通知,等.. --> <aop:pointcut id="mycut" expression="execution(* cn.com.xinli.service..*.*(..))"/> <aop:before pointcut-ref="mycut" method="doAccessCheck"/> <aop:after-returning pointcut-ref="mycut" method="doAfterReturning"/> <aop:after-throwing pointcut-ref="mycut" method="doAfterThrowing"/> <aop:after pointcut-ref="mycut" method="doAfter"/> <aop:around pointcut-ref="mycut" method="doBasicProfiling"/> </aop:aspect> </aop:config> <!-- 扫描 cn.com.xinli包下以及子包种有 @Service @Controller @Repository @Component 注解的类,一旦发现,则将其纳入到spring容器中管理 --> <!-- <bean id="persionDao" class="cn.com.xinli.dao.impl.PersionDaoBean"></bean> <bean id="persionServiceBean" class="cn.com.xinli.service.impl.PersionServiceBean" init-method="init" destroy-method="destory"> --> <!-- <constructor-arg index="0" type="cn.com.xinli.dao.PersionDao" ref="persionDao"></constructor-arg> <constructor-arg index="1" value="huxl"></constructor-arg> --> <!-- <bean id="persionServiceBean2" class="cn.com.xinli.service.impl.PersionServiceBeanFactory" factory-method="createPersionServiceBean"/> <bean id="PersionServiceBeanFactory" class="cn.com.xinli.service.impl.PersionServiceBeanFactory"></bean> <bean id="persionServiceBean3" factory-bean="PersionServiceBeanFactory" factory-method="createPersionServiceBean2"></bean> --> </beans>
测试::
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); PersionSevice ps=(PersionSevice)ctx.getBean("personService"); //ps.save("huxl"); ps.getPersonName(1);
结果:
前置通知:
进入方法
我是getPersonName()方法
后置通知
最终通知
退出方法
发表评论
-
hibernatetemplate类使用
2010-03-19 22:25 1185http://115893520.iteye.com/blog ... -
Spring 中的JdbcTemplate使用
2010-03-19 22:11 34821.JdbcTemplate的execute()方 ... -
SpringAOP 的使用(两种方式)
2009-10-22 13:42 1493使用Spring AOP 拦截 方法,给被拦截的 ... -
第30讲--Spring提供的CharacterEncoding和OpenSessionInView功能
2009-09-19 18:24 1770CharacterEncoding: 在web ... -
第29讲--为Spring集成的Hibernate配置二级缓存
2009-09-18 00:29 3375合理的使用缓存策略,往往在web开发中提高性能起到关键 ... -
第28讲--Struts与Spring集成方案2(Spring集成Struts)
2009-09-17 00:57 1606集成步骤: 1.和方案1一样需要在web. ... -
第27讲--Struts与Spring集成方案1(Struts集成Spring)
2009-09-16 08:25 1795Spring2.5+Hibernate3.3+Stru ... -
第25,26讲 --搭建和配置Spring与Hibernate整合的环境
2009-06-21 11:21 1583Spring2.5+Hibernate3.3+Stru ... -
第24讲 --使用Spring配置文件实现事务管理
2009-06-20 23:56 1747采用基于XML方式配置事务 <bean ... -
第23讲 --使用Spring注解方式管理事务与传播行为详解
2009-06-11 23:19 2233事务传播属性 REQUIR ... -
第21,22讲 --搭建和配置Spring与jdbc整合的环境+Spring集成的jdbc编码和事务
2009-06-10 08:06 2681Spring+JDBC组合开发配置数据源有两种方式: ... -
第20讲--aspectj的切入点语法定义细节
2009-06-06 17:47 3627表达式分析: expression=" ... -
第18讲 --使用Spring的注解方式实现AOP的细节
2009-06-06 15:48 1537上一讲我们使用spring注解的方式理由aop技术 ... -
第17讲 --使用Spring的注解方式实现AOP入门
2009-06-05 00:48 2253使用Spring进行面向切面(AOP)编程 要 ... -
第16讲 --使用CGLIB实现AOP功能与AOP概念解释
2009-06-04 07:42 1616当代理对象没有实现 ... -
第15讲 --使用JDK中的Proxy技术实现AOP功能
2009-06-04 07:34 2311当目标类实现了接口,我们可以使用jdk的Proxy ... -
第14讲 --让Spring自动扫描和管理Bean
2009-06-02 23:40 8734通过在classpath自动扫描方式把组件纳入sp ... -
第13讲 --Autowire注解与自动装配
2009-06-02 22:46 31001. Autowire 默认是 ... -
第12讲 --编码剖析@Resource注解的实现原理
2009-06-01 23:14 3251在这一讲开始之前,我们先学习一下jdk5.0 中的一个新 ... -
第11讲 --用@Resource注解完成属性装配
2009-05-31 22:42 7013bean的注入方式有3种: 第一种:使用构造器注 ...
相关推荐
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 ...
因为上传大小的限制,分为两部分上传,这是第二部分,第一部分会在评论中给出链接 绝对是spring攻略中文版第二版 Spring专家力作 理论与实践完美结合 问题描述→解决方案→实现方法 ... 第19章 Spring中的脚本编程
因为上传大小的限制,分为两部分上传,这是第一部分,第二部分会在评论中给出链接 绝对是spring攻略中文版第二版 Spring专家力作 理论与实践完美结合 问题描述→解决方案→实现方法 ... 第19章 Spring中的脚本编程
Spring专家力作 理论与实践完美结合 问题描述→解决方案→实现方法 第一部分 核心概念 第1章 控制反转和容器 1.1 使用容器管理组件 1.1.1 问题描述 ... 第19章 Spring中的脚本编程
二、 建立spring的配置文件 8 三、 引入spring的jar包 8 四、 测试代码: 8 五、 注意接口的使用: 8 第五课:IOC(DI)配置及应用 9 一、 什么是IOC、DI 9 二、 编辑xml文件时,没有提示 9 三、 注入类型(Injecting ...
第十九章. Web框架 19.1.简介 19.2.自动装载应用程序上下文和应用程序上下文嵌套 19.2.1. 配置 19.2.2.上下文嵌套 19.3.为ASP.NET页面进行依赖注入 19.3.1.为Web控件进行依赖注入 19.4.Master Page 19.4.1.将子页面...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...
6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...
Spring Security 参考 1 第一部分前言 15 1.入门 16 2.介绍 17 2.1什么是Spring Security? 17 2.2历史 19 2.3版本编号 20 2.4获得Spring安全 21 2.4.1使用Maven 21 Maven仓库 21 Spring框架 22 2.4.2 Gradle 23 ...
二、 建立spring的配置文件 8 三、 引入spring的jar包 8 四、 测试代码: 8 五、 注意接口的使用: 8 第五课:IOC(DI)配置及应用 9 一、 什么是IOC、DI 9 二、 编辑xml文件时,没有提示 9 三、 注入类型(Injecting ...
第3章 Spring AOP和AspectJ支持 112 3.1 启用Spring的AspectJ注解支持 113 3.1.1 问题 113 3.1.2 解决方案 113 3.1.3 工作原理 113 3.2 用AspectJ注解声明aspect 115 3.2.1 问题 115 3.2.2 解决方案...
第3章 Spring AOP和AspectJ支持 112 3.1 启用Spring的AspectJ注解支持 113 3.1.1 问题 113 3.1.2 解决方案 113 3.1.3 工作原理 113 3.2 用AspectJ注解声明aspect 115 3.2.1 问题 115 3.2.2 解决方案...
由于Spring通过代理Hibernate完成数据层的操作,所以原Hibernate的配置文件hibernate.cfg.xml的信息也转移到Spring的配置文件中: 代码 4 Spring中有关Hibernate的配置信息 1. 2. !-- 数据源的配置 //--> 3. ...
2.2.3 JavaWeb程序的配置文件 2.3 MVC模式与MvC框架 2.3.1 JSP模型1和JSP模型2 2.3.2 Web应用程序需要的基础服务 2.3.3 MVC模式概述 2.3.4 常用的MvC框架 2.4 小结 第3章 Web开发中的客户端技术 3.1 ...
2.2.3 JavaWeb程序的配置文件 2.3 MVC模式与MvC框架 2.3.1 JSP模型1和JSP模型2 2.3.2 Web应用程序需要的基础服务 2.3.3 MVC模式概述 2.3.4 常用的MvC框架 2.4 小结 第3章 Web开发中的客户端技术...
spring aop 事物处理 7. 代码生成器 (freemarker), 代码 zip 压缩打包 8. MD5加密 SHA加密(登录密码用此加密) 9. 数据库连接池 阿里的 druid。Druid在监控、可扩展性、稳定性和性能方面都有明显的优势,支持并发 ...
8.3.2hibernate配置文件 177 8.3.3configuration与sessionfactory 178 8.3.4session类 179 8.3.5hibernate中的关联关系 179 8.3.6hibernate映射文件 180 8.3.7hibernate工作原理 182 8.4项目实战——新闻内容...
第19章 使用MyEclipse开发插件 327 19.1 MyEclipse中的插件机制 327 19.2 MyEclipse使用PDE开发插件 328 19.2.1 简单的插件开发 328 19.2.2 创建一个空白的插件项目 331 19.3 RCP应用程序的开发 333 19.3.1 RCP应用...