spring-aop

Spring AOP pointcut expression method with 0 or more argument of any type throws java.lang.NullPointerException

好久不见. 提交于 2020-02-25 13:15:09
问题 I'm following a tutorial where I'm trying to use a Spring AOP pointcut expression method that accepts 0 or more arguments of any type but I'm getting a java.lang.NullPointerException. I am using Spring MVC and maven along with eclipse. Everything is working fine if I use: @Before("execution(* add*())") or @Before("execution(* add*(*))") or @Before("execution(* add*(boolean,..))") but the moment I use ".." alone @Before("execution(* add*(..))") to mean that I want that the pointcut expression

AspectJ - pointcut to match a method that has generic parameters

丶灬走出姿态 提交于 2020-02-24 06:22:20
问题 I have a generic method that accepts any type as its parameter. For example, I would like a pointcut that matches the calls made to the method only with 'String' type as its parameter. Ultimately the requirement is to limit the scope which the advices get executed for to 'String' parameters. Here is my generic class and method: public class Param<T> { public T execute(T s){ return s; } } Main class: My app makes calls to the method with both Boolean and String as parameters. public static

Self-invocation behaviour in @Configuration vs. @Component classes

 ̄綄美尐妖づ 提交于 2020-02-22 07:46:48
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

Self-invocation behaviour in @Configuration vs. @Component classes

痴心易碎 提交于 2020-02-22 07:46:45
问题 My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method1(); } @Transactional public void method2() {} } If we call method1() from outside, method1() will be executed in a transaction mode, but as it calls internally method2(), the code inside method2() will not be executed in a transaction mode. In parallel, for a Configuration class, normally we should have the same behaviour: @Configuration class

Spring AOP pointcut for annotated argument

[亡魂溺海] 提交于 2020-02-19 09:27:40
问题 Say I have a method like so: public void method(@CustomAnnotation("value") String argument) Is there a pointcut expression that could select all methods with arguments annotated with @CustomAnnotation? If so is there a way I could get access go the "value" argument? 回答1: On selecting your arguments : @Before("execution(* *(@CustomAnnotation (*)))") public void advice() { System.out.println("hello"); } ref : http://forum.springsource.org/archive/index.php/t-61308.html On getting the annotation

What jars do I need for Spring AOP for version 5

折月煮酒 提交于 2020-02-06 07:54:49
问题 As of version 4 of Spring, these are the jars needed to use Spring AOP: aopalliance.jar aspectjrt.jar aspectjweaver.jar cglib-nodep-2.1_3.jar spring-aop-4.0.0.M2.jar But for version 5, what are the jars needed other than spring-aop-5.0.2.RELEASE.jar spring-aspects-5.0.2.RELEASE.jar And where do I find them? 回答1: Following are the minimum set of dependencies that I required to run an annotations based Spring applciation spring-context-5.2.2.RELEASE.jar spring-beans-5.2.2.RELEASE.jar spring

@AspectJ pointcut for all methods inside package

。_饼干妹妹 提交于 2020-01-30 19:41:12
问题 I have this working code for a specific package, but i want to configure it for all controllers , service and dao packages Eg com.abc.xyz.content.controller com.abc.xyz.content.service com.abc.xyz.content.dao com.abc.xyz.category.controller com.abc.xyz.category.service com.abc.xyz.category.dao and so on. . . that is the base package of my project, can someone please help how I can go about doing it so that it works for all classes of my web project including controllers, thanks in advance. .

Spring AOP pointcut expression for Subclass only method

冷暖自知 提交于 2020-01-25 10:10:31
问题 I have a scenario in which i need to intercept some subclass methods, but i couldn't find a proper pointcut expression to do so. I have a client facing interface InfoService which has a method getClientDetails . package sample; public interface InfoService { InfoVO getClientDetails(int id); } The implementation class has some nested methods like get*Info() . package sample; public class InfoServiceImpl implements InfoService{ public InfoVO getClientDetails(int id) { InfoVO clientInfo = new

Why aspect not triggered for owner side in OneToOne relationship?

泄露秘密 提交于 2020-01-25 08:42:29
问题 For example, I have a bidirectional one-to-one relationship: public class Document { @OneToOne(mappedBy = "document", cascade = CascadeType.ALL) private DocumentMetadata documentMetadata; } public class DocumentMetadata { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "document_id") private Document document; } When I save the Document entity by using Spring Data, it also saves the DocumentMetadata entity: DocumentMetadata documentMetadata = DocumentMetadata.builder() /*some fields are

Spring AOP - @Pointcut: @Before advice for @Test methods does not work

孤人 提交于 2020-01-23 09:58:30
问题 I am working with: Spring Framework 4.3.2 AspectJ 1.8.9 JUnit Gradle The project is based in multi-modules. In src/main/java ( main ) I have some @Aspect classes and they work how is expected. I can confirm it through Runtime and Testing Now I need for JUnit through logging show the @Test method name that is executed Therefore in src/test/java ( test ) I have the following: class TestPointcut { @Pointcut("execution(@org.junit.Test * *())") public void testPointcut(){} } @Aspect @Component