Spring MVC:在切入点中正式解除绑定
Spring MVC: formal unbound in pointcut
我的 Spring Web 模型-视图-控制器 (MVC) 框架中有这个 class。我正在使用面向方面的编程 (AOP),这是一种编程范例,旨在通过允许分离横切关注点来增加模块化。
这个 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 请求作为参数,因此我将方法修改为
@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
只是意味着您的建议声明了一个未被相应切入点使用(绑定)的参数(反之亦然)。您可以通过 args()
、this()
、target()
、@annotation()
等将参数绑定到通知方法参数
具体问题是在您的建议中声明了参数HttpServletRequest request
。价值应该从哪里来?相应的切入点似乎拦截了另一个方面的通知方法,该方法没有任何 HttpServletRequest
类型的参数。因此,只要您没有可以获取 servlet 请求的来源,您就必须自己创建一个实例。
我的印象是您需要先多了解一点 AOP。随意 post 更多代码并解释你想从哪里获取对象,然后我可能会帮助你修复你的代码。
我的 Spring Web 模型-视图-控制器 (MVC) 框架中有这个 class。我正在使用面向方面的编程 (AOP),这是一种编程范例,旨在通过允许分离横切关注点来增加模块化。 这个 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 请求作为参数,因此我将方法修改为
@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
只是意味着您的建议声明了一个未被相应切入点使用(绑定)的参数(反之亦然)。您可以通过 args()
、this()
、target()
、@annotation()
等将参数绑定到通知方法参数
具体问题是在您的建议中声明了参数HttpServletRequest request
。价值应该从哪里来?相应的切入点似乎拦截了另一个方面的通知方法,该方法没有任何 HttpServletRequest
类型的参数。因此,只要您没有可以获取 servlet 请求的来源,您就必须自己创建一个实例。
我的印象是您需要先多了解一点 AOP。随意 post 更多代码并解释你想从哪里获取对象,然后我可能会帮助你修复你的代码。