我是AOP的新手.我有这样的问题.
package org.suman.Aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LoginAspect {
//@Before("execution(public String getName())")
//@Before("execution(public String org.suman.Model.Triangle.getName())")
//@Before("execution(* get*())")
//@Before("execution(* get*(..))")
//@Before("execution(* org.suman.Model.*.get*())")
//@Before("execution(* get*())&& within(org.suman.Model.Circle)")
@Before("execution(* get*())&& allCircle()")
//@Before("allGetters() && allCircle()")
public void LoginAdvice()
{
System.out.println("Advice run.. getMethod is called");
}
@Before("execution(* get*())")
//@Before("allGetters()")
public void SecondAdvice()
{
System.out.println("this is a second Advice");
}
@Pointcut("execution(* get*())")
public void allGetters(){}
//@Pointcut("execution (* * org.suman.Model.Circle.*(..))")
@Pointcut("within(org.suman.Model.Circle)")
public void allCircle(){}
}
Run Code Online (Sandbox Code Playgroud)
当使用切入点时,方法allGetters()为LoginAdvice方法,如果我使用@Before("execution(*get*())"然后没有错误但是如果我使用@Before("allGetters()")则会给出错误" java.lang.IllegalArgumentException::: 0处的错误找不到引用的切入点allGetters
如果我使用@Before("execution(*get*())&&(org.suman.Model.Circle)")而不是方法名称,它可以工作.
我的xml是这样的:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- <context:annotation-config /> -->
<aop:aspectj-autoproxy />
<bean name="triangle" class="org.suman.Model.Triangle">
<property name="name" value="Triangle Name"></property>
</bean>
<bean name="circle" class="org.suman.Model.Circle">
<property name="name" value="Circle name"></property>
</bean>
<bean name="shapeService" class="org.suman.Services.ShapeService"
autowire="byName"></bean>
<bean name="loginAspect" class="org.suman.Aspect.LoginAspect"></bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
请通过切入点解决问题的方法
For*_*e_7 25
我有这个问题 - 在'占位符'方法上使用@Pointcut给了我"找不到引用的切入点"错误.
简单地通过使用maven依赖项更新AspectJ库来解决:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
对此
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我相信您需要在前面放置另一个通配符:
@Pointcut("execution(* get*())")
Run Code Online (Sandbox Code Playgroud)
将其更改为:
@Pointcut("execution(* *get*())")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23435 次 |
| 最近记录: |