springAOP配置文件

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <beans
  3     xmlns="http://www.springframework.org/schema/beans"
  4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5     xmlns:aop="http://www.springframework.org/schema/aop"
  6     xmlns:tx="http://www.springframework.org/schema/tx"
  7     xmlns:p="http://www.springframework.org/schema/p"
  8     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  9         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 10            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
 11     <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
 12         <property name="driverClassName">
 13             <value>com.mysql.jdbc.Driver</value>
 14         </property>
 15         <property name="url">
 16             <value>jdbc:mysql://localhost:3306/ssh2</value>
 17         </property>
 18         <property name="username">
 19             <value>root</value>
 20         </property>
 21         <property name="password">
 22             <value>123456</value>
 23         </property>
 24     </bean>
 25     <!-- 配置sessionFactory -->
 26     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 27         <property name="dataSource" ref="dataSource"></property>
 28         <property name="hibernateProperties">
 29             <props>
 30                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
 31                 <prop key="hibernate.show_sql">true</prop>
 32             </props>
 33         </property>
 34         <property name="mappingResources">
 35             <list>
 36                 <value>com/zhanghaobo/bean/User.hbm.xml</value>
 37             </list>
 38         </property>
 39     </bean>
 40     <!-- 配置事务管理器 -->
 41     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 42         <property name="sessionFactory" ref="sessionFactory"></property>
 43     </bean>
 44     <!-- 哪些类哪些方法使用事务 -->
 45     <aop:config>
 46         <!-- 定义在哪些方法上开启事务-->
 47         <aop:pointcut expression="execution(* com.zhanghaobo.service.impl.*.*(..))" id="allManagerMethod"/>
 48         <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
 49         <aop:aspect id="authorAspect" ref="authorityInterceptor">
 50             <aop:before method="checkAuthor" pointcut-ref="allManagerMethod"/>
 51         </aop:aspect>
 52     </aop:config>
 53     <!-- 事务的传播特性  -->
 54     <tx:advice id="txAdvice" transaction-manager="transactionManager">
 55         <tx:attributes>
 56             <tx:method name="find*" propagation="REQUIRED" read-only="true" />
 57             <tx:method name="*" propagation="REQUIRED"/>
 58         </tx:attributes>
 59     </tx:advice>
 60     <bean id="authorityInterceptor" class="com.zhanghaobo.interceptor.AuthorityInterceptor">
 61         <property name="user">
 62             <value>aaa</value>
 63         </property>
 64     </bean>
 78     <bean id="userService" class="org.springframework.aop.framework.ProxyFactoryBean" >
 79         <property name="target" ref="userServiceTarget"></property>
 80         <property name="proxyInterfaces">
 81             <value>com.zhanghaobo.service.UserService</value>
 82         </property>
 83
 84         <property name="interceptorNames">
 85             <value>authorityInterceptor</value>
 86         </property>
 87     </bean>
 88     <bean id="userDao" class="com.zhanghaobo.dao.impl.UserDAOImpl" scope="singleton">
 89         <property name="sessionFactory" ref="sessionFactory"></property>
 90     </bean>
 91     <bean id="userServiceTarget" class="com.zhanghaobo.service.impl.UserServiceImpl" scope="singleton">
 92         <property name="userdao" ref="userDao"></property>
 93     </bean>
 94     <bean id="saveUserAction" class="com.zhanghaobo.action.user.SaveUserAction" scope="prototype">
 95         <property name="userService" ref="userService"></property>
 96     </bean>
 97     <bean id="listUserAction" class="com.zhanghaobo.action.user.listUser" >
 98         <property name="userService" ref="userService"></property>
 99     </bean>
100 </beans>
时间: 2024-08-03 10:58:53

springAOP配置文件的相关文章

7.spring:SpringAOP(配置文件)

SpringAOP(xml文件配置) 配置文件的方式,主要是在xml文件中进行配置,不使用注解! 目录: AtithmeticCalculator.java public interface AtithmeticCalculator { int add(int i,int j); int sub(int i,int j); int mul(int i,int j); int div(int i,int j); } AtithmeticCalculatorImp1.java @Component

spring-AOP之通知和顾问

通知和顾问都是切面的实现形式,其中通知可以完成对目标对象方法简单的织入功能. 而顾问包装了通知,可以让我们对通知实现更加精细化的管理,让我们可以指定具体的切入点. 通知分为前置通知,环绕通知及后置通知. 前置通知:在目标方法执行之前执行,不改变方法的执行流程及执行结果,前置通知的实现类要实现"MethodBeforeAdvice"这个接口. 环绕通知:也叫方法拦截器,可以改变方法的执行流程及执行结果,环绕通知的实现类要实现"MethodInterceptor"这个接

SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-009-带参数的ADVICE2 配置文件为XML

一. 1.配置文件为xml时则切面类不用写aop的anotation 1 package com.springinaction.springidol; 2 3 public class Magician implements MindReader { 4 private String thoughts; 5 6 public void interceptThoughts(String thoughts) { 7 System.out.println("Intercepting volunteer

关于Spring配置文件xml文档的schema约束

最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. [html] view plain copy print? <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:m

Spring-AOP实践

Spring-AOP实践 公司的项目有的页面超级慢,20s以上,不知道用户会不会疯掉,于是老大说这个页面要性能优化.于是,首先就要搞清楚究竟是哪一步耗时太多. 我采用spring aop来统计各个阶段的用时,其中计时器工具为StopWatch. 文章结构: 遇到的问题 创建项目 AOP-HelloWorld 时间统计 bug final 压力测试 源码 其中,遇到的问题: 1.少包aspectjweaver 添加依赖后才可以使用@Aspect 2.环绕通知加入多个point 刚开使用&&连

spring applicationContext.xml 配置文件 详解

applicationContext.xml 文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http

Spring-AOP用法总结

前言     Spring AOP的实现方法很多,在项目开发中具体采用什么方式,需要按实际情况来选择,每一种的用法,有其一定的实用价值,所以本文将各种使用方法进行了具体实现.主要包括Advice的before.after.throwing.around四种拦截方式的实现,如何进行正则匹配,自动化代理及AspectJ注解形式的实现. AOP的定义 Spring AOP(Aspect-oriented programming) 面向切面编程,是一种特殊的拦截器,将一组程序中的公共部分抽离出来进行单独

XML配置文件的命名空间与Spring配置文件中的头

一直以来,写Spring配置文件,都是把其他配置文件的头拷贝过来,最多改改版本号,也不清楚哪些是需要的,到底是干嘛的.今天整理一下,拒绝再无脑copy. 一.Spring配置文件常见的配置头 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http:/

SpringAOP与Redis搭建缓存

SpringAOP与Redis搭建缓存 近期项目查询数据库太慢,持久层也没有开启二级缓存,现希望采用Redis作为缓存.为了不改写原来代码,在此采用AOP+Redis实现. 目前由于项目需要,只需要做查询部分: 数据查询时每次都需要从数据库查询数据,数据库压力很大,查询速度慢,因此设置缓存层,查询数据时先从redis中查询,如果查询不到,则到数据库中查询,然后将数据库中查询的数据放到redis中一份,下次查询时就能直接从redis中查到,不需要查询数据库了. redis作为缓存的优势: 1.内存