spring-aop

Spring: register advice programmatically at runtime

天涯浪子 提交于 2019-12-04 13:10:29
Is it possible to register AOP advices programmatically, after the application has booted and the context has been initialized? When I tried, the advices didn't work, supposedly because they need to wrap the bean BEFORE it gets available in the context. Something like this (it doesn't work): @Bean private AspectJExpressionPointcutAdvisor createPointcutAdvisor(AWSXRayRecorder awsxRayRecorder, String name, String pointcut) { AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor(); advisor.setExpression("execution ...()"); advisor.setAdvice(new CustomAdvice("custom bean"

How can I run common code for most requests in my Spring MVC Web App?

你说的曾经没有我的故事 提交于 2019-12-04 12:18:17
问题 i.e. I have various URLs mapped using Spring MVC RequestMapping @RequestMapping(value = "/mystuff", method = RequestMethod.GET) @RequestMapping(value = "/mystuff/dsf", method = RequestMethod.GET) @RequestMapping(value = "/mystuff/eee", method = RequestMethod.GET) etc I want to run some common action before about 90% of my requests. These are across several controllers. Is there anyway to do that without delving into AOP? And if I have to use aspects, any guidance on how to do this?! Thanks!

Spring aop pointcut expression to access method return type

☆樱花仙子☆ 提交于 2019-12-04 11:03:01
问题 I have a service interface with many methods, all of which take a Request object and return a Response object. All request objects have a common ancestor and all response objects have a different common ancestor (which has a success flag and a message field). Now I want to have an around aspect that checks permissions etc, performs the service call and returns a Response object with a failure code if anything fails. The problem is: I need to know what type of Response object to create. Is

Why in Spring AOP the object are wrapped into a JDK proxy that implements interfaces?

别来无恙 提交于 2019-12-04 11:02:29
问题 I am studying Spring and I have the followig Consider the following bean definition: <bean id="clientService" class="com.myapp.service.ClientServiceImpl" /> Now consider the case on which it is declared a pointcut* targetting all methods inside the **clientService bean. Consider also that the ClientServiceImpl class implements 3 interfaces Now I know that using AOP the clientService bean is proxied and that this proxy implements all the 3 interfaces. But what is the exact reason for which all

Do method profiling ( Basic execution time ) With Spring AOP

試著忘記壹切 提交于 2019-12-04 10:52:46
问题 I'm looking for a feature or software, who will allow me to easily profile my method execution time and choose what to profile by package filter. I know, it's profiler 101. I use the TPTP profiler. But I'm not happy with it. To be frank I just don't understand how it works, and when I profile my application (launch the server in profiling mode), it takes forever to do nothing. (well, not what I expect: a simple output of execution time) So I do the profiling myself with system time (add a

Spring AOP Exclude Some Classes

断了今生、忘了曾经 提交于 2019-12-04 10:19:06
问题 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

Spring aop intercepting calls from within the same service class

帅比萌擦擦* 提交于 2019-12-04 10:04:04
I have a same scenario as mentioned in Spring @Transaction method call by the method within the same class, does not work? I was referring to answer #1 which i thought would work for my simple pojo class but it didnt. In my case i dont have annotation @Transaction. Its a simple pojo class. I wish to intercept each method adduser as well as addusers using spring aop if i take example in post above. Is it possible to intercept method that is being called from the same service call? I was referring to AspectJAwareProxy which does the trick but doesnt resolve the issue as a whole. What i mean is i

Access a business method's local variable in a method which is in an ASPECT

和自甴很熟 提交于 2019-12-04 06:16:29
I want to access a local variable from a method in a business class, in a method which is in an aspect class. For instance class BusinessClass { public void simpleTest() { ... String localString = new String( "test" ); ... } } MyAspect { log() { // I WANT TO ACCESS THE VALUE OF LOCALSTRING HERE } } I want to access localString's value in log method of MyAspect. Please let me know if there is any way to accomplish this using Spring / AspectJ. Also, is there is a way to accomplish without changing simpleTest method signature? Thanks much in advance! As I understand them, aspects are intended to

Why my Aspect is not detected for Jersey controller (using custom annotation)?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:41:02
I want to create an Aspect over a Jersey controller to measure how long the services take to be executed. I'm fighting against my pointcut since it isn't detected and my aspect never gets launched. I have tried using lots of pointcuts like: execution(@Monitor * *.*(..)) execution(public * *(..)) change the order of @Aspect and @Component Added a pointcut like this: @Pointcut("execution(@Monitor * *.*(..))") public void monitorRequestTargets(){} @Around("monitorRequestTargets()") Tried using AOP and CGLIB <aop:aspectj-autoproxy proxy-target-class="true"/> Also tried changing the order of

How to pool objects in Spring?

天涯浪子 提交于 2019-12-04 05:31:11
I'm following this tutorial regarding how to pool objects in Spring. I've followed the instruction written on the tutorial but when I run my application, it always generates a new instance of the object. I'm expecting that since I'm pooling the objects, existing objects will be reuse. As such, no new instances should be created. Also, when I access of the getter method of the bean, a new instance of the bean is created again. What could have I done wrong? Did I misunderstood the concept of pooling in Spring? Below is my code: Application Context: (This is just the body of my application