Spring MVC:切入点中的正式绑定 [英] Spring MVC: formal unbound in pointcut
问题描述
我的Spring Web模型-视图-控制器(MVC)框架中有此类.我正在使用面向方面的编程(AOP),这是一种编程范例,旨在通过允许跨领域关注点的分离来提高模块化. 这个课程一切都很好
I have this class in my Spring Web model-view-controller (MVC) framework. I am using aspect-oriented programming (AOP), a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Everything is fine with this class
@Aspect
public class MarketingAspect extends ServiceSupport {
@Pointcut("execution(* com.tdk.iot.services.client.LicenseService.*(..))")
public void handleServiceMethod() {
}
@Pointcut("execution(* com.tdk.iot.services.client.ApplicantService.*(..))")
public void handleApplicantServiceMethod() {
}
@Before("com.tdk.iot.services.aop.ApplicantAspect.handleServiceMethod()")
public void before(JoinPoint _jp) {
User user = getLDAPUser();
if(user != null &&( (user.getUserRole() != UserRole.MARKETING)) {
throw new NoSufficientRoleException(user == null ? null : user.getUserRole(), UserRole.MARKETING);
}
}
@Before("com.tdk.iot.services.aop.ApplicantAspect.handleApplicantServiceMethod()")
public void checkRolebefore(JoinPoint _jp) {
User user = getLDAPUser();
if(user != null &&( (user.getUserRole() != UserRole.MARKETING))) {
throw new NoSufficientRoleException(user == null ? null : user.getUserRole(), UserRole.MARKETING);
}
}
}
我更改了方法表示法getLDAPUser,现在接收HttpServletRequest请求作为参数,因此我将方法修改为
I have changed the method notation getLDAPUser and now receives HttpServletRequest request as a parameter, so I modified the method as
@Before("com.tdk.iot.services.aop.ApplicantAspect.handleApplicantServiceMethod()")
public void checkRolebefore(JoinPoint _jp, HttpServletRequest request) {
User user = getLDAPUser(request);
if(user != null &&( (user.getUserRole() != UserRole.MARKETING))) {
throw new NoSufficientRoleException(user == null ? null : user.getUserRole(), UserRole.MARKETING);
}
}
修改此方法后,出现此错误
and after modified this method I got this ERROR
java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
在我的XML中:
<!-- Scan for aspects -->
<aop:aspectj-autoproxy />
<bean id="marketingAspect" class="com.tdk.iot.services.aop.MarketingAspect" />
推荐答案
首先,AspectJ基础知识:错误formal unbound in pointcut
仅仅意味着您的建议声明了相应切入点未使用(绑定)的参数(反之亦然).您可以通过args()
,this()
,target()
,@annotation()
等将参数绑定到建议方法参数.
First the AspectJ basics: The error formal unbound in pointcut
simply means that your advice declares a parameter not used (bound) by the corresponding pointcut (or vice versa). You can bind parameters to advice method parameters via args()
, this()
, target()
, @annotation()
etc.
具体问题是在您的建议中声明了参数HttpServletRequest request
.价值从何而来?相应的切入点似乎拦截了另一个方面的建议方法,该方法没有任何类型为HttpServletRequest
的参数.因此,只要您没有源即可使用servlet请求,就必须自己创建一个实例.
The concrete problem is that in your advice you declare the parameter HttpServletRequest request
. Where should the value come from? The corresponding pointcut seems to intercept another aspect's advice method which does not have any parameter of type HttpServletRequest
. So as long as you do not have a source you can tap for the servlet request, you will have to create an instance by yourself.
我的印象是,您需要首先了解有关AOP的更多信息.随时发布更多代码并解释您要从何处获取对象,然后我可能会帮助您修复代码.
My impression is you need to learn a bit more about AOP first. Feel free to post more code and explain where you want to get the object from, then I can probably help you fix your code.
这篇关于Spring MVC:切入点中的正式绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!