spring-aop

AspectJ Load time weaver doesn't detect all classes

我的未来我决定 提交于 2019-12-03 05:38:50
I am using Spring's declarative transactions (the @Transactional annotation) in "aspectj" mode. It works in most cases exactly like it should, but for one it doesn't. We can call it Lang (because that's what it's actually called). I have been able to pinpoint the problem to the load time weaver. By turning on debug and verbose logging in aop.xml, it lists all classes being woven. The problematic class Lang is indeed not mentioned in the logs at all. Then I put a breakpoint at the top of Lang , causing Eclipse to suspend the thread when the Lang class is loaded. This breakpoint is hit while the

Spring AOP Exclude Some Classes

混江龙づ霸主 提交于 2019-12-03 05:29:49
I'm using Spring AspectJ for logging method execution statistics, however, I want to exclude some classes and methods from this without changing the pointcut expression. To exclude certain methods I created a custom annotation which I use to filter out. However I'm unable to do the same with classes. Here is my aspect definition - @Around("execution(* com.foo.bar.web.controller.*.*(..)) " + "&& !@annotation(com.foo.bar.util.NoLogging)") public Object log(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { // logging logic here } NoLogging is my custom annotation for excluding methods.

Spring AOP: “no declaration can be found for element 'aop:config' ”

拜拜、爱过 提交于 2019-12-03 05:18:09
问题 I've seen that a few instances of this problem have been raised already. However, I am confident that I satisfy the criteria that has been outlined in those solutions. i.e. I'm pretty sure I have the desired jars on my class path + my schemalocation addresses look in order. One solution mentioned that the issue can be caused by having another XML parser on the classpath. I do have dom4j on my classpath but I have removed it to test, and the problem persists. Here's my classpath: <?xml version

Spring AOP (Aspect) Not executing

假装没事ソ 提交于 2019-12-03 05:02:45
I ams using Spring 2.5.6, asm 1.5.3, aspectjrt/aspectjweaver 1.6.1, cglib 2.1_3 In my Web based Spring application I have following class: package uk.co.txttools.aspects; @Aspect public class LoggingAspect { @Before("execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.set*(..))") public void setLoggingAdvice(){ System.out.println("********************************* Advice run..... set mothod called...."); } @AfterThrowing("execution(* uk.co.txttools.web.controller.compose.PreviewMessageController.onSubmit(..) throws java.lang.Exception)") public void hadleException(){

How to inject HttpServletRequest into a Spring AOP request (custom scenario)?

房东的猫 提交于 2019-12-03 02:33:42
I know the standard way of writing an AOP advice around a controller method and that you can get access to the HttpServletRequest arg, if declared in controller method. But my scenario is that I have a translation service, that is currently session-scoped maintaining the user's locale for translation. I feel this makes the service stateful and also I do not want it to be session-scoped, as I think it is really Singleton. But there are multiple places where the translation service methods are called and so I do not want to change the signature to add request/locale in these methods. The problem

Spring AOP target() vs this()

北战南征 提交于 2019-12-02 22:47:18
From Spring Documentation : any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface: this(com.xyz.service.AccountService) any join point (method execution only in Spring AOP) where the target object implements the AccountService interface: target(com.xyz.service.AccountService) I don't understand what "target object" and the expression target(...) mean. How is target different from this ? this(AType) means all join points where this instanceof AType is true. So this means that in your case once the call reaches any method of AccountService

Spring AOP: “no declaration can be found for element 'aop:config' ”

一曲冷凌霜 提交于 2019-12-02 18:33:44
I've seen that a few instances of this problem have been raised already. However, I am confident that I satisfy the criteria that has been outlined in those solutions. i.e. I'm pretty sure I have the desired jars on my class path + my schemalocation addresses look in order. One solution mentioned that the issue can be caused by having another XML parser on the classpath. I do have dom4j on my classpath but I have removed it to test, and the problem persists. Here's my classpath: <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src

Using Ajc compiler with Spring problem AspectJ

泪湿孤枕 提交于 2019-12-02 13:52:09
问题 when i am trying to aspectj with spring using ajc compiler ,i am getting following errror.when i am removing aspectj then code is working fine is there anything with the compile time weaving which is causing problem caused by: java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance

Java Aspect returned value to be used in the method

谁说胖子不能爱 提交于 2019-12-02 13:15:21
问题 I have an @After java aspect that runs certain logic. I need it to return a result (an object) that can be used in the methods intercepted by the aspect's pointcut. Is it possible? 回答1: What you need is @Around which allows you to return whatever you want to the advised object: @Around("com.xyz.myapp.UserService.createUser()") public Object userCreationAdvice(ProceedingJoinPoint pjp) throws Throwable { //Do something if needed before method execution Object retVal = pjp.proceed(); //Do

Spring AOP: How to determine if method threw an exception using @After?

拈花ヽ惹草 提交于 2019-12-02 10:56:10
Spring docs say: After advice must be prepared to handle both normal and exception return conditions. @After("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") public void doReleaseLock() { // ... } I'm interested in knowing whether dataAccessOperation completed normally or with an exception. Unfortunately, the above code snippet is in the run for the most useless documentation ever produced. I understand that I can use AfterReturning and AfterThrowing separately, or even Around , but that's not the point. Since After exists, I should be able to use it. What the documentation wants to