spring-aop

Exception handling and after advice

浪子不回头ぞ 提交于 2019-12-20 07:27:12
问题 I am using AOP with spring boot. After some method execution successfully I am using @After advice in AOP to do some data base insertion. There is one case if the method throw an exception somewhere then I don't want to execute my @After advice call. I don't have any idea if I catch exception in AOP also my after advise method will going to execute. @After(value = "execution(* saveUpdateMeasures(..)) and args(addMeasure)") public void afterAdviseMeasure(JoinPoint joinPoint,AddMeasures

Error: java.lang.NoSuchMethodError: org/springframework/asm/ClassVisitor.<init>(I)V

跟風遠走 提交于 2019-12-20 06:15:22
问题 I have these two dependencies in my POM which are i think creating this issue but i have tried many different ways and updated versions but nothing worked for me. Can someone please help. POM.XML <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.2.0.RELEASE</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> 回答1: Solution to your Question It seems there is a JAR

Applying custom annotation advice to spring data jpa repository

女生的网名这么多〃 提交于 2019-12-20 05:25:30
问题 I am working on a mysql master slave replication. I am using spring data jpa(spring boot). What I needed is all write operations to go to master server and read-only operations to be equally distributed among multiple read-only slaves. For that I need to: Use special JDBC driver: com.mysql.jdbc.ReplicationDriver Set replication: in the URL: spring: datasource: driverClassName: com.mysql.jdbc.ReplicationDriver url: jdbc:mysql:replication://127.0.0.1:3306,127.0.0.1:3307/MyForum?user=root

How to write an annotation/aspect to not enter a method but return null if a given condition is false?

眉间皱痕 提交于 2019-12-20 05:22:33
问题 I currently have a requirement where I need to return null from 100s of methods if a given condition is false. I was thinking of using Java Annotations or Spring Aspects for this so that I don't have to write that if-else block of code everywhere. Any idea as to how we can do this using Java Annotations or Spring Aspects? Any pointers might be helpful. 回答1: If I get you correctly, Spring @Conditional annotation is what you want. You create some public class that implements Spring's Condition

aop.xml name and location?

点点圈 提交于 2019-12-20 04:52:44
问题 Is there a way to specify the name of the aop.xml file with LTW? or define another name and location? I have several software modules that I use and that all use META-INF/aop.xml with different settings. I include these modules in a web application and then it all dependens how it's deployed/unpacked, which aop.xml file is used .. So I discovered after long time of searching that not all LTW weaving toke place correcting as it depends with aop.xml was used ... Basically I need to use both aop

Aspect for method annotated with annotation which are annotated with another annotation

佐手、 提交于 2019-12-20 04:10:18
问题 Is it possible to make pointcut using Spring AOP for methods and type having annotation which was annotated with some annotation. Here's my custom annotation: @AccessRestriction @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface HasPermission { } It annotated with this annotation: @Target({ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface AccessRestriction { } So is it possible to create point cut which will

Spring AOP point cut for 'nested' annotation

丶灬走出姿态 提交于 2019-12-20 03:30:22
问题 I need to define a point cut which triggers the execution on all methods of a spring service annotated with a custom annotation. The annotation I would like to define the point cut on will be on an other annotation. @Y public @interface X { } and then the service would be annotated as following @X public Service1 { } I tried with the following point cut definition but it only works when @Y is on the service itself, meaning that it doesn't see that the annotation is on @X @Around("@within(com

Spring: cannot inject a mock into class annotated with the @Aspect annotation

♀尐吖头ヾ 提交于 2019-12-20 02:39:18
问题 I created a Before advice using AspectJ: package test.accesscontrol.permissionchecker; import test.accesscontrol.database.SessionExpiredException; import test.database.UsersDatabaseAccessProvider; import test.common.constants.GlobalConstants; import test.common.model.AbstractRequest; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.beans.factory.annotation.Autowired; @Aspect public class

Original interface is lost in Spring AOP introduction

你。 提交于 2019-12-19 10:41:53
问题 Here is my Spring AOP configuration. <bean id="myObject" class="com.madzone.learn.spring.aop.OriginalClass"></bean> <bean id="aspect" class="com.madzone.learn.spring.aop.AspectClass"></bean> <aop:config> <aop:aspect ref="aspect"> <aop:declare-parents types-matching="com.madzone.learn.spring.aop.OriginalClass+" implement-interface="com.madzone.learn.spring.aop.IntroducedInterface" default-impl="com.madzone.learn.spring.aop.IntroducedInterfaceImpl" /> </aop:aspect> ApplicationContext context =

Original interface is lost in Spring AOP introduction

十年热恋 提交于 2019-12-19 10:41:23
问题 Here is my Spring AOP configuration. <bean id="myObject" class="com.madzone.learn.spring.aop.OriginalClass"></bean> <bean id="aspect" class="com.madzone.learn.spring.aop.AspectClass"></bean> <aop:config> <aop:aspect ref="aspect"> <aop:declare-parents types-matching="com.madzone.learn.spring.aop.OriginalClass+" implement-interface="com.madzone.learn.spring.aop.IntroducedInterface" default-impl="com.madzone.learn.spring.aop.IntroducedInterfaceImpl" /> </aop:aspect> ApplicationContext context =