spring-aop

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

烈酒焚心 提交于 2019-12-07 01:19:46
问题 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

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

旧城冷巷雨未停 提交于 2019-12-06 17:20:13
问题 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 { ..

Spring AOP with groovy: get called method

大城市里の小女人 提交于 2019-12-06 12:51:13
问题 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

Make object spring managed

心不动则不痛 提交于 2019-12-06 12:11:23
How can I get an already existing object spring managed? I would like to hook it up to Springs AoP capabilities using aspectj . I know this to be a challenge since Spring AoP uses dynamic proxies which probably are created along with the object. Why do I need this? I have a third-party class which takes a constructor argument which is only known in runtime , hence it seems I cannot add it to my applicationContext or use springs FactoryBean interface for construction. Is there any other way? I've already tried the following without great success: Obj obj = new ThirdPartyObj("runtime constructor

Using spring AOP aspect to intercept the methods?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 12:10:54
问题 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? 回答1: Private methods may not be intercepted, as they may not be invoked

How can I log private methods via Spring AOP?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 10:34:41
问题 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. 回答1: You have to use compile time weaving instead of the proxy usage for Spring AOP.

Listing Aspect-proxied beans in Spring

血红的双手。 提交于 2019-12-06 10:08:52
Is there a way to get the list of beans proxied with a specific Aspect by Spring? We have an aspect on some beans that stopped working, and we are trying to figure out what happened, so I created a class to scan the ApplicationContext after it has been loaded @Component public class AspectScanner implements ApplicationListener<ContextRefreshedEvent> { public static final Logger LOGGER = LoggerFactory.getLogger(AspectScanner.class); @Override public void onApplicationEvent(ContextRefreshedEvent event) { final ApplicationContext applicationContext = event.getApplicationContext();

A bunch of questions on Spring 3 framework

十年热恋 提交于 2019-12-06 08:33:44
问题 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

How can I separate business logic and email sending functionality?

荒凉一梦 提交于 2019-12-06 08:30:30
I have a requirement in my java web application where I need to send email alerts for certain conditions. For this I have used javax mail api and sending email works just fine. But the problem is the programs executions waits until the methods for sending the email are executed. As there are hundreds of email to be sent at various points ... this reduces the performance significantly. I am using spring and have also used spring aop. Can anyone suggest me how can I separate my business logic and sending email functionality. It should be like - Sending emails is my advice which gets executed

Spring: register advice programmatically at runtime

会有一股神秘感。 提交于 2019-12-06 07:28:04
问题 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