aspectj

Pointcut matching methods with annotated parameters

左心房为你撑大大i 提交于 2019-11-26 23:09:49
问题 I need to create an aspect with a pointcut matching a method if: it is annoted with MyAnnotationForMethod One of its parameters (can have many) is annotated with @MyAnnotationForParam (but can have other annotations as well). The aspect class look like this @Pointcut("execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) && args(obj)") void myPointcut(JoinPoint thisJoinPoint, Object obj) { } @Before("myPointcut(thisJoinPoint , obj)") public void doStuffOnParam

一次栈溢出问题的排查 StackOverflowError

倖福魔咒の 提交于 2019-11-26 22:28:16
栈溢出的原因 在解决栈溢出问题之前,我们首先需要知道一般引起栈溢出的原因,主要有以下几点: 是否有递归调用,循环依赖调用 是否有大量循环或死循环 全局变量是否过多 局部变量过大,如:数组、List、Map数据过大 问题现象 我们一个很老的接口(近一年没有动过)在线上运行一段时间后报了 StackOverflowError 栈溢出,其他接口又能正常提供服务,错误日志: java.lang.StackOverflowError org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1303) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org

execution Vs. call Join point

余生长醉 提交于 2019-11-26 22:23:23
I have two different aspect classes to count the number of non-static method calls for an execution of a test program. The first aspect counts methods on "call" join points: pointcut methodCalls() : call (!static * test..*(..)); before(): methodCalls() { counter.methodCallCounter(); } while the second aspect counts methods on "execution" join points: pointcut methodCalls() : execution (!static * test..*(..)); before(): methodCalls() { counter.methodCallCounter(); } methodCallCounter() is a static method in counter class. The number of method calls for small test program is the same. But when I

Spring AOP Advice on Annotated Controllers

拥有回忆 提交于 2019-11-26 22:21:56
问题 I am trying to use AOP to do some processing after an annotated controller. Everything is running with no errors, but the advice is not being executed. Here is the controller code: @Controller public class HomeController { @RequestMapping("/home.fo") public String home(ModelMap model) { model = new ModelMap(); return "home"; } } and the setup in application-config <aop:aspectj-autoproxy/> <bean id="testAdvice" class="com.test.TestAdvice"> </bean> <bean id="testAdvisor" class="org

AspectJ pointcut expression match parameter annotations at any position

倾然丶 夕夏残阳落幕 提交于 2019-11-26 21:13:49
问题 I'm trying to define a pointcut expression to match methods which contain a parameter annotated with a specific annotation, regardless of what position the parameter is in. In my case I'm looking for the @Constraint annotation. For example: Matching methods: public void method1(@Constraint Car car) public void method2(String id, @Constraint Plane plane) public void method3(Wheel wheel, @Constraint List<Train> trains, @Constraint Plane plane) public void method4(Motor motor, @Constraint Set

AspectJ in Android: pointcut call(* Activity.onCreate(..)) doesn't pick out Activity.onCreate() calls

南笙酒味 提交于 2019-11-26 20:29:13
问题 I am using AspectJ in my Android project and I'd like to write a pointcut that catches all the calls to onCreate() and onDestroy() of my activities. I am quite new to AspectJ, so probably I am missing something here but why this: pointcut createActivity(Activity a) : target(a) && execution(* Activity.onCreate(..)) && within(com.test.activities..*); works and this: target(a) && call(* Activity.onCreate(..)) && within(com.test.activities..*); doesn't work? 回答1: Nice to see other people

logging with AOP in spring?

走远了吗. 提交于 2019-11-26 19:20:18
问题 I am new to spring in my office . So there is no guidance for me. I need to implement the logging with the AOP using the log4j . I have implemented the logging without AOP in basic spring MVC example ? Also did the small sample in AOP using the aspectJ without logging (just made the Sysout ) ? I don't know how to integrate it ? Can any one please give me a start up idea? Good answers are definitely appreciated ... 回答1: Spring makes it really easy for us to make use of AOP. Here's a simple

Emulate annotation inheritance for interfaces and methods with AspectJ

若如初见. 提交于 2019-11-26 16:41:33
Often people ask AspectJ questions like this one, so I want to answer it in a place I can easily link to later. I have this marker annotation: package de.scrum_master.app; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Inherited @Retention(RetentionPolicy.RUNTIME) public @interface Marker {} Now I annotate an interface and/or methods like this: package de.scrum_master.app; @Marker public interface MyInterface { void one(); @Marker void two(); } Here is a little driver application which also implements the interface:

Aspectj overwrite an argument of a method

痴心易碎 提交于 2019-11-26 16:37:28
问题 I'm developing an aspect that checks arguments of setter methods and overwrites empty strings with null value. This is my state so far: @Before("execution(* de.foo.entity.*.set*(..)) && args(java.lang.String)") public void check(final JoinPoint jp) { LOGGER.debug(jp.getSignature().toLongString()); Object[] args = jp.getArgs(); for (int i = 0; i < args.length; i++) { if (args[i] instanceof String && ((String) args[i]).isEmpty()) { args[i] = null; } } } Unfortunately the overwrite statement

How to instrument / advice a Spring Data (JPA) repository?

爱⌒轻易说出口 提交于 2019-11-26 16:18:44
问题 I'm failing in my effort to advice a spring data jpa repository. The goal is to instrument (around) all non- void public methods in a particular repository annotated with a custom annotation (ResourceNotFound in this example) and throw an exception when the return value is either null or an empty collection. @Repository @ResourceNotFound @Transactional(readOnly = true) public interface CityRepository extends JpaRepository<City, Long>, JpaSpecificationExecutor<City> { … } The following advice