KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have written simple Aspect with primitive Pointcut and Advise method: @Aspect public class MyAspect { @Pointcut("execution(static * com.mtag.util.SomeUtil.someMethod(..))") public void someMethodInvoke() { } @AfterReturning(value = "someMethodInvoke())", returning = "comparisonResult") public void decrementProductCount(List<String> comparisonResult) { //some actions } } I have following Spring annotation-based application config: @Configuration @EnableAspectJAutoProxy public class AppConfig { //... } And utility class in com.mtag.util package: public class SomeUtil { static List<String> someMethod(List<String> oldList, List<String> newList) { //... } } but when I call SomeUtil.someMethod(arg1, arg2); in unit test I can see that method call is not intercepted and my @AfterReturning advise is not working. But if i change someMethod() type to instance (non-static) method, pointcut to @Pointcut("execution(* com.mtag.util.SomeUtil.someMethod(..))") and manage SomeUtil bean by Spring by adding @Component annotation and call target metod like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppConfig.class}, loader = AnnotationConfigContextLoader.class) public class SomeUtilTest { @Autowired private SomeUtil someUtil; @Test public void categoriesDiffCalc() { List<String> result = someUtil.someMethod(...); } } Everything is OK. In what way I can set an Advice for static method?
Tags (comma-separated)
Save Edits
Cancel