spring-aop

spring annotation advice order

爱⌒轻易说出口 提交于 2019-12-05 05:53:08
I have a method with two annotations @One @Two public Object foo() { ... } I have two aspects that use these annotations @Around("@annotation(One)") public Object doOne(final ProceedingJoinPoint joinPoint) throws Throwable { ... } and @Around("@annotation(Two)") public Object doTwo(final ProceedingJoinPoint joinPoint) throws Throwable { ... } But is the order in which these advices are executed indeterminate? The order is undefined. If you need determinate order, use @Order annotation. See also: 7.2.4.7 Advice ordering 6.2.4.7. Advice ordering What happens when multiple pieces of advice all

Why do i need cglib (Spring AOP) to have multiple test classes?

≡放荡痞女 提交于 2019-12-05 04:17:37
I have a spring application and I make my test class as follows: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/META-INF/spring/applicationContext.xml" }) @TransactionConfiguration(defaultRollback = true) @Transactional public class MyTest { } When I try to create another test class and tried to run the application, I get the following exception on the new test class: ERROR [main] (TestContextManager.java:324) - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecut r@22e85825] to

Spring AOP with groovy: get called method

此生再无相见时 提交于 2019-12-04 21:02:53
I'm using spring aop with groovy and have a monitoring aspect that should log each method's execution time. The problem is groovy calls are not the same as java calls so the following code always prints "getMetaClass()" as method name. @Before("execution(* mypackage.MyService.*(..))") void beforeMethod(JoinPoint joinPoint) { logger.info(joinPoint.signature.name + " called") } I see two ways to solve the problem: Find the actual method from the groovy call Use some other way to get the called method (instead of injecting jointPoint argument) Any ideas? For Option 1: Try adding a !getMetaClass()

Spring AOP: is there a way to make @target work for indirect annotations?

这一生的挚爱 提交于 2019-12-04 20:46:37
I have an annotation: @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) public @interface MyAnnotation { } I annotate Spring MVC controllers with it: @MyAnnotation public class TestController { ... } Then I add an advice which has the following: @Pointcut("@target(MyAnnotation)") public void annotatedWithMyAnnotation() {} @Around("annotatedWithMyAnnotation()") public Object executeController(ProceedingJoinPoint point) throws Throwable { ... } Advice's method is invoked successfully. Now I have a bunch of controllers sharing the same

Can not set field to com.sun.proxy.$Proxy

南楼画角 提交于 2019-12-04 19:25:35
问题 For file upload I am trying to inject and use a Validator in my Spring Controller like this: @RestController @RequestMapping("/api") public class FileController{ @Autowired private MessageSource messageSource; @Autowired FileValidator validator; @InitBinder("file") public void initBinderFile(WebDataBinder binder) { binder.setValidator(validator); } @RequestMapping(value = "/fileUpload2", method = RequestMethod.POST, produces = {"text/plain"}) @PreAuthorize("hasAuthority('ADMINISTRATOR')")

Log4j and AOP, how to get actual class name

ぃ、小莉子 提交于 2019-12-04 18:30:36
问题 I'm implementing a logger as an aspect using Spring AOP and Log4J, but I've noticed that the class name in log file is always the LoggerAspect class name, so... is there a way to trace the actual class name in my log? 回答1: @Around("execution(* com.mycontrollerpackage.*.*(..))") public Object aroundWebMethodE(ProceedingJoinPoint pjp) throws Throwable { String packageName = pjp.getSignature().getDeclaringTypeName(); String methodName = pjp.getSignature().getName(); long start = System

Using spring AOP aspect to intercept the methods?

梦想的初衷 提交于 2019-12-04 16:47:13
I am using spring AOP to intercept the methods. I have below configuration in my spring config file. <aop:aspectj-autoproxy /> Aspect class: @Aspect public class MyAspect{ @Around("execution(public * *(..))") public Object doAction(ProceedingJoinPoint call) throws Throwable { //somelogic } Above method does not intercept private methods ? what should i do to ask the aspect to intercept both private and public methods? Private methods may not be intercepted, as they may not be invoked through a proxy. However, you could use native AspectJ weaving, as you can see on the point 8.8.4 of the

How can I log private methods via Spring AOP?

吃可爱长大的小学妹 提交于 2019-12-04 16:41:42
I am not able to log the private methods using spring aop performance logging. Below is the configuration I am using below configuration <aop:config proxy-target-class="true"> <aop:pointcut id="allServiceMethods" expression="execution(* com.mycom.app.abc..*.*(..))"/> <aop:advisor pointcut-ref="allServiceMethods" advice-ref="performanceMonitor" order="2"/> </aop:config> I am having cglib jar on my class path. You have to use compile time weaving instead of the proxy usage for Spring AOP. From Spring AOP - Supported Pointcut Designators Due to the proxy-based nature of Spring’s AOP framework,

AspectJ Pointcut on Methods with Multiple Annotations

瘦欲@ 提交于 2019-12-04 15:31:54
Use load-time weaving, pure AspectJ. We have 2 annotations @Time and @Count , and a few annotated methods. @Time (name="myMethod1Time") @Count (name="myMethod1Count") public void myMethod1(){..}; @Time (name="myMethod2Time") public void myMethod2(){..}; @Count (name="myMethod3Count") public void myMethod3(){..}; Now I am defining my own around aspect for myMethod1 which has multiple annotations: // multiple annotations, not working @Around("@annotation(time) && @annotation(count)) public Object myAspect(Time time, Count count) {..} This doesn't work. However, capture method myMethod2 works

A bunch of questions on Spring 3 framework

ぐ巨炮叔叔 提交于 2019-12-04 14:18:02
Here are the questions resulted from reading the Spring Reference, please help. (1) Do I ever need manual creation of ApplicationContext? Do I ever need second instance of AplicationContext? (2) We have the following config instructions: <context:annotation-config/> <context:component-scan base-package=".."/> <mvc:annotation-driven/> Do these instructions duplicate theirselfs? In which cases yes, in which no? (3) I am a bit stuck with all that ways Spring introduces to convert from string to object: PropertyEditor, Conversions, Formatting.. Here is a simple use case: I have a Spring MVC