标签: aspectj

Spring 3.0 aop Pointcut格式不正确:期待'名称模式'错误

以下是我的切入点和建议声明

//PointCut on A method which takes two parameters and is in a DAO
@Pointcut("execution(backend.repository.QuestionsRepository.AnswerQuestion (..))")
public void answerQuestionPointCut() {}


@Around(
   value="web.activity.advisors.UserActivityAdvisor.answerQuestionPointCut()",
   argNames="question,answer"
)

 // Do something

}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 65
execution(backend.repository.QuestionsRepository.AnswerQuestion (..))
                                                                 ^
Run Code Online (Sandbox Code Playgroud)

我坚持这个,任何指针

java aop spring aspectj spring-aop

9
推荐指数
1
解决办法
3万
查看次数

如何使用Spring AOP(AspectJ样式)访问方法属性?

我需要通过使用注释作为切入点来接受一些方法及其属性,但是如何访问这些方法属性.我有以下代码,可以在方法运行之前成功运行代码,但我只是不知道如何访问这些attrbiutes.

package my.package;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class MyAspect {

 @Pointcut(value="execution(public * *(..))")
 public void anyPublicMethod() {
 }

 @Around("anyPublicMethod() && @annotation(myAnnotation )")
 public Object myAspect(ProceedingJoinPoint pjp, MyAnnotation myAnnotation)
    throws Throwable {

  // how can I access method attributes here ?
  System.out.println("hello aspect!");
  return pjp.proceed();
 }
}
Run Code Online (Sandbox Code Playgroud)

java aop aspectj spring-aop

9
推荐指数
2
解决办法
2万
查看次数

了解Spring AOP

我正在使用Spring 3.0框架,仍然是一个新手.任何人都可以用非专业术语解释我的AOP编程是什么?(一个简短的例子肯定会有帮助)

Spring如何整合/增强/支持它?

java aop spring aspectj

9
推荐指数
4
解决办法
7727
查看次数

AspectJ JoinPoint问题

我目前正在使用JoinPoint捕获在运行时传递给服务方法的参数.虽然JoinPoint帮助我检索参数值,但我发现当传递的参数是数组时,我没有提供任何好的API来检索参数名称,参数类型,单个参数值等.

这是一个例子:

public void doIt(String user, Attribute[] attr, Integer[] i, boolean bool, List<Attribute> list){.....}
Run Code Online (Sandbox Code Playgroud)

对于上面的方法,当我使用JoinPoint.getArgs()时,我看到参数的垃圾值,它是一个数组或集合.如果参数是数组或集合,我如何验证它们是否是其中之一以及如何遍历它们以检索单个值?

有什么建议 ?谢谢

aspectj

9
推荐指数
1
解决办法
9655
查看次数

是否可以在具有Hibernate和AspectJ的Java项目中使用SBT?

我需要配置什么以及自动运行什么?据我所知,使用两者都可能有点棘手,因为两者都使用字节码编织.我可以继续使用更方便的配置语法,还是需要"完整"的Scala版本?

目前我正在尝试使用Maven,但没有取得多大成功.

java hibernate aspectj maven sbt

9
推荐指数
1
解决办法
437
查看次数

是否可以检索使用AspectJ执行方法调用的对象实例?

让我们想象以下方面:

 aspect FaultHandler {

   pointcut services(Server s): target(s) && call(public * *(..));

   before(Server s): services(s) {
     // How to retrieve the calling object instance?
     if (s.disabled) ...;
   }

 }
Run Code Online (Sandbox Code Playgroud)

切入点捕获对公共方法的所有调用,Server并在调用before任何这些方法之前运行建议.

是否可以检索在通知中执行对公共Server方法的调用的对象实例before?如果有,怎么样?

java aspectj

9
推荐指数
1
解决办法
4822
查看次数

禁用/避免在AspectJ中执行建议

假设我有一个方面

public aspect Hack {

pointcut authHack(String user, String pass): call(* Authenticator.authenticate(String,String)) && args(user,pass);

boolean around(String user, String pass): authHack(user,pass) {
    out("$$$ " + user + ":" + pass + " $$$");
    return false;
}

}
Run Code Online (Sandbox Code Playgroud)

这种Authenticator.authenticate方法很重要.黑客拦截对此方法的调用.

是否有可能编写第二个方面来取消/禁用authHackHack方面的建议?

我可以捕获around authHack建议的执行,但如果我想继续身份验证,我需要Authenticator.authenticate再次调用,这会创建一个无限循环..

java aop aspectj

9
推荐指数
1
解决办法
3446
查看次数

AspectJ - 获取带注释的方法参数的值

我创建了自定义注释@MyAnn.我将使用它来注释方法参数.

例如: public static call(@MyAnn String name){...}

使用AspectJ,如何访问和更新使用注释注释的所有参数的值?

我发现展示了如何创建切入点瞄准定制标注,一些示例代码在这里.

所以现在,我用切入点创建了一个方面.但我不知道热得到参数注释的值MyAnn.

@Aspect
public class MyAnnAspect {

    @Around("execution(@my.package.test.MyAnn") // I hope this pointcut will work
    public void changeParameter(final ProceedingJoinPoint pjp) throws Throwable {
        // How I can there get parameter value (and chage it)? 
    }
}
Run Code Online (Sandbox Code Playgroud)

java aspectj

9
推荐指数
1
解决办法
9055
查看次数

Spring AOP:@annotation(注释)

我(当然)试图使用许多我不太了解的结构来维护项目.在试图弄清楚Spring中的AOP使用的过程中,我遇到了带有以下注释的方法:

@Around(value ="@ annotation(annotation)")

所以@Around意味着我们在AOP中执行方法切入点的'around'版本,我明白了.我不知道其他部分是什么意思.Spring文档提供以下内容:

@annotation - 限制连接点的匹配,其中连接点的主题(在Spring AOP中执行的方法)具有给定的注释

我不知道这意味着什么 - "在Spring AOP中执行的方法"听起来像建议的方法,但我不知道我(或Spring)如何找出建议的方法.听起来它是具有"给定注释"的方法,但如果是这样,那么给出了什么注释?

这个注释建议了哪些方法?还有什么意思呢?

java aop spring annotations aspectj

9
推荐指数
1
解决办法
2万
查看次数

@EnableAspectJAutoProxy不起作用

我正在使用Spring Boot,我想使用AspectJ.

以下作品(当然):

@Aspect
@Component
public class RequestMappingAspect {

    @Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void advice(JoinPoint joinPoint) {
        ...
    }
}

但是,如果@Component删除并@EnableAspectJAutoProxy添加,则以下操作无效.

@SpringBootApplication
@EnableSwagger2
@EnableAspectJAutoProxy
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

如何正确启用AspectJ自动代理?

java spring aspectj

9
推荐指数
2
解决办法
8817
查看次数

标签 统计

aspectj ×10

java ×9

aop ×5

spring ×4

spring-aop ×2

annotations ×1

hibernate ×1

maven ×1

sbt ×1