spring-aop

Exception in thread “main” java.lang.ClassCastException: com.sun.proxy.$Proxy13 cannot be cast to CustomeClass

有些话、适合烂在心里 提交于 2019-12-23 04:56:26
问题 I am trying to learn AOP with Spring Framework, but there is one exception that keeps on getting invoked. Error : Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy13 cannot be cast to com.controller.Triangle Shape.java package com.controller; public interface Shape { public void draw(); } Triangle.java package com.controller; import org.springframework.stereotype.Component; @Component public class Triangle implements Shape { public void draw() { System.out.println(

Exception in thread “main” java.lang.ClassCastException: com.sun.proxy.$Proxy13 cannot be cast to CustomeClass

Deadly 提交于 2019-12-23 04:56:24
问题 I am trying to learn AOP with Spring Framework, but there is one exception that keeps on getting invoked. Error : Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy13 cannot be cast to com.controller.Triangle Shape.java package com.controller; public interface Shape { public void draw(); } Triangle.java package com.controller; import org.springframework.stereotype.Component; @Component public class Triangle implements Shape { public void draw() { System.out.println(

Which Interface's (extending CrudRepository) delete method was triggered using spring AOP?

扶醉桌前 提交于 2019-12-23 03:48:11
问题 @Repository public interface UserRepository extends JpaRepository<User, Long> { } I am calling userRepo.deleteById(1) from my service layer and using spring AOP I want to log the Interface name whenever any deleteById is called so that I can track which interface's deleteById was triggered. I want an output which can give me a clue of the interface name. joinPoint.getSignature() returns the generic name i.e. void org.springframework.data.repository.CrudRepository.deleteById(Object) and but I

Spring AOP Pointcut expression for annotated field

☆樱花仙子☆ 提交于 2019-12-23 03:43:07
问题 Is it possible to capture any field with a specific annotation? My end goal is to inject a value into that field, but currently my pointcut is wrong (not sure of the correct syntax). @Pointcut("execution(* *(..)) && @annotation(com.mycompany.MyAnnotation)") private void annotatedField(){} @Around("annotatedField()") public Object injectValue(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {} I believe the pointcut is stating any Method with the annotation. and I want to change

Make object spring managed

余生长醉 提交于 2019-12-23 01:12:54
问题 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

Make object spring managed

爱⌒轻易说出口 提交于 2019-12-23 01:12:14
问题 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

Self-invocation shouldn't be adviced but it does

与世无争的帅哥 提交于 2019-12-22 15:02:55
问题 I'm getting a weird behavior by Spring AOP AspectJ: self-invocation shouldn't be adviced, but in my application it does. From Spring documentation: However, once the call has finally reached the target object, the SimplePojo reference in this case, any method calls that it may make on itself, such as this.bar() or this.foo(), are going to be invoked against the this reference, and not the proxy. This has important implications. It means that self-invocation is not going to result in the

How can I separate business logic and email sending functionality?

让人想犯罪 __ 提交于 2019-12-22 12:44:48
问题 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

Service bean failed to inject in spring cglib proxy

痞子三分冷 提交于 2019-12-22 10:35:40
问题 I have an annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface PartnerProxy { } And a Advice @Component @Aspect public class AnnotationAdvice { @Around("@annotation(PartnerProxy)") public Object pc(ProceedingJoinPoint joinPoint) throws Throwable { return joinPoint.proceed(); } } And the bean i want to proxy public class OuterServiceProxy { private IRoomStatusService service; ... another properties String getRemoteHourRoomStatus(){ return service.echo();

SpringAOP introductions with AspectJ

混江龙づ霸主 提交于 2019-12-22 09:16:02
问题 I'm new in SpringAOP. I want to write simple example of Introductions but can't understand clearly how it must work. In documentation I find that: Introduction: declaring additional methods or fields on behalf of a type. Spring AOP allows you to introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type