【Spring五】AOP之使用注解配置
| < context:component- scan base-package= "cn.itheima03.spring.aop.annotation" ></context :component-scan> |
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-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" >
<!--
1、把全部的bean放入到spring容器中,启动类扫描机制的注解
2、启动AOP的注解
-->
<context:component-scan base-package="cn.itheima03.spring.aop.annotation" ></context:component-scan>
<aop:aspectj-autoproxy></ aop:aspectj-autoproxy>
</beans>
|
|
//配置注解,须要产生实例
@Repository("classesDao" )
public class ClassesDaoImpl extends HibernateUtils implements ClassesDao{
public String
saveClasses(Classes classes) { sessionFactory.getCurrentSession().save(classes);
return "aaaa" ;
}
public List<Classes>
getClasses() { return sessionFactory .getCurrentSession().createQuery("from
Classes").list(); }
public void updateClasses(Classes
classes) { sessionFactory.getCurrentSession().update(classes);
}
}
=============================
/**
* @Aspect该注讲解明该类是一个切面类 ,等效于:
* <aop:aspect ref="myTransaction">
* <aop:pointcut expression="execution(* cn.itheima03.spring.aop.annotation.ClassesDaoImpl.*(..))"
* id=" aa()"/>
* </aop:aspect>
*/
@Component("myTransaction" )
@Aspect
public class MyTransaction extends HibernateUtils{
private Transaction transaction;
@Pointcut("execution(*
cn.itheima03.spring.aop.annotation.ClassesDaoImpl.*(..))") private void aa(){} //方法签名
方法的修饰符最好为private,返回值必须是void @Before("aa()")
public void beginTransaction(){
this.transaction = sessionFactory.getCurrentSession().beginTransaction();
}
@AfterReturning( "aa()")
public void commit(){
this.transaction .commit();
}
}
|
【Spring五】AOP之使用注解配置的更多相关文章
- 黑马Spring学习 AOP XML和注解配置 5种通知 切点切面通知织入
业务类 package cn.itcast.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoin ...
- Spring的AOP配置文件和注解实例解析
1.1 Spring的AOP配置文件和注解实例解析 AOP它利用一种称为"横切"的技术,将那些与核心业务无关,却为业务模块所共同调用的逻辑或责任封装起来,便于减 ...
- MongoDB和Java(5):Spring Data整合MongoDB(注解配置)
最近花了一些时间学习了下MongoDB数据库,感觉还是比较全面系统的,涉及了软件安装.客户端操作.安全认证.副本集和分布式集群搭建,以及使用Spring Data连接MongoDB进行数据操作,收获很 ...
- Spring(十五):通过注解配置 Bean
在ClassPath中扫描组件 1)组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件: 2)特定组件包含: --- @C ...
- Spring(五)AOP简述
一.AOP简述 AOP全称是:aspect-oriented programming,它是面向切面编号的思想核心, AOP和OOP既面向对象的编程语言,不相冲突,它们是两个相辅相成的设计模式型 AOP ...
- 深入学习Spring框架(二)- 注解配置
1.为什么要学习Spring的注解配置? 基于注解配置的方式也已经逐渐代替xml.所以我们必须要掌握使用注解的方式配置Spring. 关于实际的开发中到底使用xml还是注解,每家公司有着不同的使用习惯 ...
- Spring IOC机制之使用注解配置bean
一. 通过注解配置bean 1.1 概述 相对于XML方式而言,通过注解的方式配置bean更加简洁和优雅,而且和MVC组件化开发的理念十分契合,是开发中常用的使用方式. 1.2 ...
- spring aop自动代理注解配置之二
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- spring aop自动代理注解配置之一
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
随机推荐
- 移动端Web开发如何处理横竖屏
<!Doctype html> <html> <head> <meta charset="utf-8"> <meta id=& ...
- Day22 JSONP、瀑布流
一.JSONP JSONP a.Ajax $.ajax({ url:'/index/', dataType:'json', data:{}, type:'GET', success:function( ...
- odoo 错误 Resource interpreted as Stylesheet but transferred with MIME type application/x-css:
odoo8 页面内容显示一半, web 控制台显示错误 Resource interpreted as Stylesheet but transferred with MIME type ap ...
- 使用spm build 批量打包压缩seajs 代码
一,安装环境 1.安装spm spm工具是基于node(nodejs的服务平台)的,因此我们需要先安装 node 和 npm 下载地址:http://nodejs.org/#download.下载完成 ...
- 【Java】servlet和servlet 容器
servlet不是线程安全的,它通过多线程方式运行其service方法,一个实例可以服务于多个请求,并且其实例一般不会销毁,所以你的项目中如果只有一个servlet,那么web容器就只会创建一个实例 ...
- VC++6.0 编写插件(图文并茂)
下午偶然注意到VC++6.0新建工程标签页下的DevStudio Add-in Wizard,没有接触过,看名字是给Developer Studio开发插件,心生喜感,于是百度之,发生百度检索几乎找不 ...
- Delphi在win7/vista下写注册表等需要管理员权限的解决方案
看到论坛好多人问win7下写注册表的问题,我结合自己的理解写了一点东西,首先声明一下,本人初学Delphi,水平有限,大家见笑了,有什么不对之处请老鸟多指点. [背景]win7/Vista提供的UAC ...
- lingo运筹学上机实验指导
<运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...
- 什么是系统,什么是算法 -- lemon OA 系统学习总结
一.对于模块划分的理解 对于一个大型(这里还只是一个中型系统)系统来说,代码的编写不是一日而就的,层次的明细也不是一眼就能看清楚的. 在这种情况下,需要想好,最好是由上而下地想好. 能够模块式地划分最 ...
- 2015第43周一solr相关概念
Solr是一种开放源码的.基于Lucene的搜索服务器.它易于安装和配置,而且附带了一个基于HTTP 的管理界面. 官网:http://lucene.apache.org/solr/ solr学习 ...