【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 ...
随机推荐
- andriod 开发记录apidemos 错误解决
android sdk 里面有simple 文件夹里面有对应的demo 但是拿出来esplise运行报错 解决方案如下 右键错误代码goto,给对应错误的单引号前加 \ 原文http://stack ...
- sql server 数据库基础学习心得 思维导图
- [转]基于Spring + Spring MVC + Mybatis 高性能web构建
http://blog.csdn.net/zoutongyuan/article/details/41379851/ 一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.Angula ...
- 从零开始学习MySQL2---MySQL的安装与配置(只有Windows)
因为我电脑只装了Windows系统,故而,只整理了在Windows系统下的安装方式 截图比较麻烦,故而多引用百度经验. Windows平台下安装与配置MySQL 5.6 下载,网址:http://de ...
- BZOJ 3969 low power
Description 有\(n\)个机器,每个机器有\(2\)个芯片,每个芯片可以放\(k\)个电池.每个芯片能量是\(k\)个电池的能量的最小值.两个芯片的能量之差越小,这个机器就工作的越好.现在 ...
- 如何使用 Docker、ECS、Terraform 重建基础架构?
早期 Segment 基础架构普遍组合在一起.我们通过 AWS 界面设定实例,使用许多闲散的 AMI,并且采用三种不同的部署方式. 然而随着商业的飞速发展,工程师团队的规模不断扩大,基础架构的复杂度也 ...
- Life Forms
poj3294:http://poj.org/problem?id=3294 题意:就是求n个串的中一个最大的子串,这个子串在超过n/2的串中出现. 题解:这是一道好题.首先一种解法就是用后缀数组来搞 ...
- 【POJ2778】AC自动机+矩阵乘法
DNA Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14758 Accepted: 5716 Descrip ...
- BlockingQueue队列学习
今天看了下BlockingQueue的几种实现,记录下以便以后复习. 首先来看一下BlockingQueue的家族成员: BlockingQueue除了先进先出外,还有两个操作:在队列为空时,获取元素 ...
- Hibernate+jxl+excel导入数据库
在将excel中的10w行数据导入数据库中时,总发生内存溢出,一开始使用的Spring+Hibernate;不知如何使用批处理,后来只是用Hibernate,10W行数据几分钟完成, 代码如下: pu ...