在Controller中使用AOP
转:http://usherlight.iteye.com/blog/1306111
在Controller中使用AOP的问题主要在于如何让Controller能够被检测到。
Controller和其他Spring bean的区别在于:Controller是由mvc定义并在web.xml中的dispatcher中定义的。
解决方法:
1、正确定义Controller,(比较通用的做法,没有特殊情况的话,大部分应用没有这个问题)
a. 将服务层的类都放在ApplicationCotext-*.xml中定义,在context listener中初始化(注意,任何Controller都不应该在这里出现),要包括<aop:aspectj-autoproxy/>, 在这里,有没有proxy-target-class="true" 没有关系(具体含义参看下文)
b. 定义mvc的配置文件,一般是 <<servlet name>>-servlet.xml,一般(也是推荐做法)使用auto scan来定义所有的Controller.关键步骤来了:这个文件也要加入<aop:aspectj-autoproxy proxy-target-class="true"/>, 一定要添加proxy-target-class="true"! 这是用于通知Spring使用cglib而不是jdk的来生成代理方法。
c. 另外一个事项,Controller需要使用@Controller注释,而不是继承abstract Controller。
d. 建议使用aspectj来完成aop
在Controller中使用AOP的更多相关文章
- spring aop在mvc的controller中加入切面无效
spring aop在mvc的controller中加入切面无效 因为MVC的controller,aop默认使用jdk代理.要使用cglib代理. 在spring-mybatis.xml配置文件中加 ...
- .Net中的AOP系列之《方法执行前后——边界切面》
返回<.Net中的AOP>系列学习总目录 本篇目录 边界切面 PostSharp方法边界 方法边界 VS 方法拦截 ASP.NET HttpModule边界 真实案例--检查是否为移动端用 ...
- Spring拦截器中通过request获取到该请求对应Controller中的method对象
背景:项目使用Spring 3.1.0.RELEASE,从dao到Controller层全部是基于注解配置.我的需求是想在自定义的Spring拦截器中通过request获取到该请求对应于Control ...
- 在SpringBoot中配置aop
前言 aop作为spring的一个强大的功能经常被使用,aop的应用场景有很多,但是实际的应用还是需要根据实际的业务来进行实现.这里就以打印日志作为例子,在SpringBoot中配置aop 已经加入我 ...
- Spring中的AOP 专题
Caused by: java.lang.IllegalArgumentException: ProceedingJoinPoint is only supported for around advi ...
- springmvc的controller中使用@Transactional无效
最近看mybatis的时候做了一个练习,但是进行事务处理的时候出了问题,如下 package com.henu.lz.controller; import org.springframework.be ...
- Spring的Aspect切面类不能拦截Controller中的方法
根本原因在于<aop:aspectj-autoproxy />这句话是在spring的配置文件内,还是在springmvc的配置文件内.如果是在spring的配置文件内,则@Control ...
- spingAOP在springMVC中的使用(我用在拦截controller中的方法。主要用于登录控制)
首先截取了网上的一张配置execution的图片 我在项目中关于aop的配置:如果拦截controller的方法,需要在spring-mvc.xml文件中加入(如果在spring.xml中加入则无法拦 ...
- 利用多态,实现一般处理程序(ashx)中的AOP(切面编程)
本文是对工作中的项目进行代码优化(完善登陆验证的AOP切面编程)时,所遇到的各种解决方案思考过程. 项目背景:由ashx+nvelocity构建的简单B/S问卷系统,现需要优化登录验证环节(时隔若干个 ...
随机推荐
- layer ajax请求
layer ajax请求 $.ajax({ // url: '../php/creatSceneXml.php', url: '../php/action.php', type: 'POST', da ...
- C++序列容器之 vector常见用法总结
一.关于vector 本文默认读者具有一定的c++基础,故大致叙述,但保证代码正确. vector是一个动态的序列容器,相当于一个size可变的数组. 相比于数组,vector会消耗更多的内存以有效的 ...
- PHP空对象 空数组
PHP定义空对象:$obj = (object)null;或$obj = (object)array(); 定义空数组:$arr = array();或$arr = [];//自 5.4 起可以使用短 ...
- JavaScript处理股票数据
1, 先使用Ajax发送异步请求到:http://hq.sinajs.cn/list=s_sh000001 2, 然后用[,]切割成数组https://www.w3school.com.cn/js/j ...
- 一千行MySQL学习笔记 (转)
出处: 一千行MySQL学习笔记 /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权 ...
- shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机
1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...
- AWS In Action
Core Services of AWS Elastic Cloud Compute(EC2) Simple Storage Service(S3) Relational Database Servi ...
- css样式水平居中和垂直居中的方法
水平居中(包含块中居中) 1. 定宽,左右margin为auto.(常规流块盒.弹性项目[不用定宽]) 例子:在box1盒子上设置宽,再设置margin:auto: <style> .bo ...
- Ubuntu18.10中pip install mysqlclient 出现EnvironmentError: mysql_config not found错误
Complete output from command python setup.py egg_info: sh: 1: mysql_config: not found Traceback (mos ...
- 多个分组树分别实现单选jq+angular
$scope.seletedGroup=[];var $li=$("#departmentsContainer>ol>li");$.each($li,function( ...