spring-aop

Spring AOP: get access to argument names

眉间皱痕 提交于 2019-11-29 02:24:25
I'm using Spring 3.x, Java 6. I have an @Around aspect with the following joinpoint: @Around("execution(public * my.service.*.*Connector.*(..))") So, I'm basically interested in intercepting all calls to public methods of classes with the class name ending with "Connector". So far so good. Now, in my aspect I would like to access the actual argument names of the methods: public doStuff(String myarg, Long anotherArg) myarg and anotherArg I understand that using: CodeSignature signature = (CodeSignature)jointPoint.getSignature(); return signature.getParameterNames(); will actually work but only

Using a request scoped bean outside of an actual web request

只谈情不闲聊 提交于 2019-11-29 01:14:45
I have a web application that has a Spring Integration logic running with it in a separated thread. The problem is that at some point my Spring Integration logic tries to use a request scoped bean and then i get the following errors: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.tenantContext': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are

Enable Spring AOP or AspectJ

℡╲_俬逩灬. 提交于 2019-11-28 23:13:11
问题 This is following on from this question: Spring autowired bean for @Aspect aspect is null My initial understanding was that when using Spring AOP, classes annotated with @Aspect are created as spring managed beans, so dependency injection would work as normal. However it seems that an object with the @Aspect annotation is created as a singleton outside the spring container, hence me having to configure it in XML like so in order to enable it as a spring managed bean: <bean id="aspect" class=

AspectJ pointcut for annotated PRIVATE methods

陌路散爱 提交于 2019-11-28 21:49:21
I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below. @Aspect public class ServiceValidatorAspect { @Pointcut("within(@com.example.ValidatorMethod *)") public void methodsAnnotatedWithValidated() { } @AfterReturning( pointcut = "methodsAnnotatedWithValidated()", returning = "result") public void throwExceptionIfErrorExists(JoinPoint joinPoint, Object result) { ... } Service Interface public interface UserService { UserDto createUser(UserDto userDto); } Service

Obtain real Class object for Spring bean

岁酱吖の 提交于 2019-11-28 21:15:51
I am using Spring to inject beans. And I am using some annotations to annotate bean methods (Security, TransactionManagement, ExceptionHanling, Logging). The problem is: I want to create JUnit test to check if I forgot annotate some methods. But Spring returns $ProxyXXX class without any annotations on methods.. Method[] methods = logic.getClass().getMethods(); for (Method method : methods) { Annotation[] annotations = method.getAnnotations(); // empty array! How can I get annotations for method or obtain a real class object? P.S. Spring 2.5.6, JDKDynamicProxy (not CGLib) axtavt Spring's

Java Spring AOP: Using CustomizableTraceInterceptor with JavaConfig @EnableAspectJAutoProxy, not XML <aop:advisor>

落花浮王杯 提交于 2019-11-28 18:23:20
Spring AOP has a method-level tracer called CustomizableTraceInterceptor . Using Spring's XML configuration approach, one would set up this tracer like so: <bean id="customizableTraceInterceptor" class=" org.springframework.aop.interceptor.CustomizableTraceInterceptor"> <property name="enterMessage" value="Entering $[methodName]($[arguments])"/> <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/> </bean> <aop:config> <aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))"/> <

How to get a method's annotation value from a ProceedingJoinPoint?

核能气质少年 提交于 2019-11-28 16:11:45
I have below annotation. MyAnnotation.java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { } SomeAspect.java public class SomeAspect{ @Around("execution(public * *(..)) && @annotation(com.mycompany.MyAnnotation)") public Object procede(ProceedingJoinPoint call) throws Throwable { //Some logic } } SomeOther.java public class SomeOther{ @MyAnnotation("ABC") public String someMethod(String name){ } } In above class am passing " ABC " with in @MyAnnotation . Now how can i access " ABC " value in procede method of SomeAspect.java class? Thanks! You

Spring AOP: What's the difference between JoinPoint and PointCut?

我的未来我决定 提交于 2019-11-28 14:47:21
问题 I'm learning Aspect Oriented Programming concepts and Spring AOP. I'm failing to understand the difference between a Pointcut and a Joinpoint - both of them seem to be the same for me. A Pointcut is where you apply your advice and a Joinpoint is also a place where we can apply our advice. Then what's the difference? An example of a pointcut can be: @Pointcut("execution(* * getName()") What can be an example of a Joinpoint? 回答1: Joinpoint: A joinpoint is a candidate point in the Program

Spring AspectJ, pointcut before method execution where method OR class is annotated

心已入冬 提交于 2019-11-28 14:27:31
I'm trying to get the value of an annotation via Spring Aop AspectJ-style, where the annotation can be on the class OR the method. I tried a lot of different things, but I can only get it to work when the annotation is on the method. I'd really like to annotate ONCE on the class - but advice all the methods of the class - and access the value of the class annotation in the advice. Here's where I've ended up: Annotation: @Inherited @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { String value() default ""; } Aspect: @Aspect

Unobtrusive AOP with Spring.Net

99封情书 提交于 2019-11-28 12:42:54
I'm trying to add logging to methods decorated with an attribute using Spring.Net for AOP . Step 1: Reference 'Spring.Core', 'Spring.Aop', 'Common.Logging' Step 2: Create an advice: using AopAlliance.Intercept; namespace MyApp.Aspects { public class LoggingAdvice : IMethodInterceptor { public object Invoke(IMethodInvocation invocation) { //todo: log started object rval = invocation.Proceed(); return rval; //todo: log finished } } } Step 3: Create an attribute: using System; namespace MyApp.Aspects { public class LoggingAttribute : Attribute { } } Step 4: Edit web.config <configuration>