aspectj

Aspectj: Pointcut on lambda expression

偶尔善良 提交于 2019-11-30 20:11:54
I have a Java6 project that is being migrated to Java8. We used aspectj to log some of users actions, like button clicking. So there are listeners like this: button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { doSth(); } }); And poincut: @Pointcut("execution(public void Button.ClickListener.buttonClick(Button.ClickEvent))") public void buttonClick() {}; But since we will use Java8, listeners will be like this: button.addClickListener(clickEvent -> doSth()); Is there any way to write aspectj pointcut, so that it handles new

Using AspectJ logging without Spring

心不动则不痛 提交于 2019-11-30 19:51:32
I have just working on an old application which has poor log or no logs. It does not implement Spring framework. Is it possible to implement AspectJ logging functionality without Spring? If yes please suggest me some good tutorials. try this link for a simple application showing use of Load time weaving without using Spring http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html all that would be needed is aspectj runtime and weaver jars, and a META-INF\aop.xml file containing proper config. also refer link for details about using aspectj ltw without spring http://www

Set an AspectJ advise for static method

懵懂的女人 提交于 2019-11-30 19:50:41
I have written simple Aspect with primitive Pointcut and Advise method: @Aspect public class MyAspect { @Pointcut("execution(static * com.mtag.util.SomeUtil.someMethod(..))") public void someMethodInvoke() { } @AfterReturning(value = "someMethodInvoke())", returning = "comparisonResult") public void decrementProductCount(List<String> comparisonResult) { //some actions } } I have following Spring annotation-based application config: @Configuration @EnableAspectJAutoProxy public class AppConfig { //... } And utility class in com.mtag.util package: public class SomeUtil { static List<String>

AspectJ - Creating a global Logger field using an Inter-Type Declaration

偶尔善良 提交于 2019-11-30 19:32:32
问题 I'd like to create an Inter-Type declaration that declares a (static final) Logger instance inside each class. The constructor should be passed the enclosing class Klazz.class value: @Aspect public class LoggerAspect { public interface Logger { } public static class LoggerImpl implements Logger { private static final Logger logger = new Logger(thisJoinPoint.getTarget().getClass()/*.getName()*/); } @DeclareParents(value="com.my.api..*",defaultImpl=LoggerImpl.class) private Logger

AspectJ JoinPoint question

牧云@^-^@ 提交于 2019-11-30 19:03:48
I am currently using JoinPoint to capture the parameters passed to service methods at runtime. Though JoinPoint helps me retrieve the parameter values, I see that it doesn't provide any good API to retrieve the names of the parameters, parameter types, individual parameter values when the parameter passed is an array etc. Here's an example: public void doIt(String user, Attribute[] attr, Integer[] i, boolean bool, List<Attribute> list){.....} For the above method, when I use JoinPoint.getArgs(), i see a garbage value for the parameter which is an array or a collection. If the parameter is an

AspectJ: ClassLoading issue when trying to use external aop.xml file

老子叫甜甜 提交于 2019-11-30 18:19:03
问题 I m trying to externalize the configuration of aop.xml so I removed the aop.xml from META-INF and made it available in the server for manual configuration by sys admins. When I try to use an external aop.xml using -Dorg.aspectj.weaver.loadtime.configuration="file:D:\Workspace\tomcat7\shared\lib\aop.xml" I get java.lang.RuntimeException: Cannot register non aspect: aspectclass.... mainly because the aj casses are not loaded by AppClassLoader yet at that time. And the next time it tries to

Sring如何选择JDK动态代理与CGLIB字节码增强

安稳与你 提交于 2019-11-30 16:00:04
Spring将事务代理工厂TransactionProxyFactoryBean或自动代理拦截器BeanNameAutoProxyCreator的proxyTargetClass属性,设置为true,则使用CGLIB代理,此属性默认为false,使用JDK动态代理。 Spring AOP部分使用JDK动态代理或者CGLIB来为目标对象创建代理。(建议尽量使用JDK的动态代理) 如果被代理的目标对象实现了至少一个接口,则会使用JDK动态代理。所有该目标类型实现的接口都将被代理。若该目标对象没有实现任何接口,则创建一个CGLIB代理。 如果你希望强制使用CGLIB代理,(例如:希望代理目标对象的所有方法,而不只是实现接口的方法)那也可以,但是需要考虑以下问题: 1.无法通知(advise)Final 方法,因为他们不能被覆写。 2.你需要将CGLIB 2二进制发行包放在classpath下面,与之相较JDK本身就提供了动态代理 3.强制使用CGLIB代理需要将 |aop:config| 的 proxy-target-class 属性设为true: <aop:config proxy-target-class="true"> ... </aop:config> 当需要使用CGLIB代理和@AspectJ自动代理支持,请按照如下的方式设置 <aop:aspectj-autoproxy>的

Spring AOP: exclude avoid final classes and enums from pointcut

Deadly 提交于 2019-11-30 14:42:09
I am using try to implement Logging using Spring AOP. I have defined the @Pointcut("execution(* com.mycom..*(..))") private void framework() {} @Around("framework()") public Object aroundAdviceFramework(ProceedingJoinPoint jp) throws Throwable { if (logger.isDebugEnabled()) logger.debug("DEBUG:: {} {} Enter", jp.getTarget().getClass().getName(), jp.getSignature().getName()); Object returnVal = jp.proceed(jp.getArgs()); if (logger.isDebugEnabled()) logger.debug("DEBUG:: {} {} Out", jp.getTarget().getClass().getName(), jp.getSignature().getName()); logger.info("INFO:: " + jp.getTarget().getClass

Aspectj doesn't work with kotlin

不想你离开。 提交于 2019-11-30 14:01:33
问题 i want to use aspectj aop in kotlin,here is my code: my annotation in annotation.lazy_list: Kotlin: package anotation @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION) annotation class lazy_list my aspectj aop class: @Aspect class ActiveListAop{ @Pointcut("execution(@annotation.lazy_list * *(..))") fun profile() { } @Before("profile()") fun testModeOnly(joinPoint: JoinPoint) { println("123") } } my usage: @lazy_list fun all():List<T>{ return lazy_obj?.all() as List<T>

Spring Boot, @Autowire into an unmanaged class using @Configurable and load time weaving

巧了我就是萌 提交于 2019-11-30 13:56:23
I have a collection of unmanaged classes that I are instantiated outside of Spring. I've been attempting to use Spring AOP with load time weaving to @Autowire a bean into these classes but have so far not had any luck. I've been testing using Tomcat 8 and Spring Boot 1.2.0. My @Configuration where I attempt to set up class looks like this: @Configuration @PropertySource("classpath:application.properties") @EnableSpringConfigured @EnableLoadTimeWeaving public class Config Inside Config I define the bean I want to @Auotwire into my unmanaged classes: @Bean public StateProvider stateProvider() {