gpt4 book ai didi

java - Spring MVC : formal unbound in pointcut

转载 作者:行者123 更新时间:2023-12-01 09:15:10 24 4
gpt4 key购买 nike

我的 Spring Web 模型- View - Controller (MVC) 框架中有这个类。我正在使用面向方面的编程(AOP),这是一种编程范例,旨在通过允许分离横切关注点来提高模块化性。这个类一切都很好

@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 请求作为参数,因此我将该方法修改为

@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);
}
}

修改此方法后,我收到此错误

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 只是意味着您的建议声明了相应切入点未使用(绑定(bind))的参数(反之亦然)。您可以通过 args()this()target()@annotation()< 将参数绑定(bind)到通知方法参数 等等

具体问题是在您的建议中声明了参数HttpServletRequest request。值(value)应该从哪里来?相应的切入点似乎拦截了另一个方面的通知方法,该方法没有任何 HttpServletRequest 类型的参数。因此,只要您没有可用于 servlet 请求的源,您就必须自己创建一个实例。

我的印象是您需要首先了解更多有关 AOP 的知识。请随意发布更多代码并解释您想要从哪里获取对象,然后我可能会帮助您修复代码。

关于java - Spring MVC : formal unbound in pointcut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40607883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com