aspectj

AspectJ pointcuts - get a reference to the joinpoint class and name

限于喜欢 提交于 2019-12-03 11:08:44
问题 I am using the @AspectJ style for writing aspects, to handle logging in our application. Basically I have a pointcut set up like so: @Pointcut("call(public * com.example..*(..))") public void logging() {} and then a before and after advice like so: @Before("logging()") public void entering() {...} ... @After("logging()") public void exiting() {...} I want to create a log in these methods in the following format: logger.trace("ENTERING/EXITING [" className + "." + methodName "()]"); The

java.lang.IllegalStateException: No thread-bound request found, exception in aspect

有些话、适合烂在心里 提交于 2019-12-03 10:55:01
问题 Following is my aspect: @Configurable @Aspect public class TimingAspect { @Autowired private HttpServletRequest httpServletRequest; // Generic performance logger for any mothod private Object logPerfomanceInfo(ProceedingJoinPoint joinPoint, String remoteAddress) { StringBuilder tag = new StringBuilder(); if (joinPoint.getTarget() != null) { tag.append(joinPoint.getTarget().getClass().getName()); tag.append("."); } tag.append(joinPoint.getSignature().getName()); StopWatch stopWatch = new

Maven project not being treated as Java in Eclipse

烈酒焚心 提交于 2019-12-03 09:48:39
I'm working on a project that has lots of different Maven projects. I've been doing a bunch of JUnit testing on these projects, and usually this goes well. I open up Eclipse, right click in package explorer->Import... Existing Maven Projects and I'm able to import the project fine. I can build, drill down to src/test/java... Right click on the file and do a Run As JUnit test. Every now and then though, I can't get this to work. If I right click to do a Run As, all I get is AspectJ/Java application. There's no JUnit tests. I noticed that the icon next to the project folder only has an M and a

Gradle + RoboBinding with AspectJ + Lombok are not compatible together

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to integrate in Android project on Gradle following libraries: Lombok RoboBinding with AspectJ Dagger In order to use RoboBinding with AspectJ and android tools 1.1.0 I compiled aspectj-plugin with this fix . All libraries are using some compile time annotation processing. I found that Lombok isn't compatible with AspectJ. I noticed that annotation processor from RoboBinding is using apt whereas lombok works only with provided (Dagger works with both). I found also Lombok and AspectJ workaurond for Maven but I don't know if

AspectJ - Weaving with custom ClassLoader at runtime

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to load classes at runtime and weave them with some AspectJ aspects at this point. I have load-time weaving enabled, and it works when I use it more conventionally. I have the following in my @Aspect class: @Before("call(* mypackage.MyInterface.*())") public void myInterfaceExecuteCall(JoinPoint thisJoinPoint, JoinPoint.StaticPart thisJoinPointStaticPart, JoinPoint.EnclosingStaticPart thisEnclosingJoinPointStaticPart) { System.out.println(thisJoinPoint.getSignature().getDeclaringType()); System.out.println(thisJoinPoint

Set an AspectJ advise for static method

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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

Mvn clean install tomcat7:deploy fails with “invalid byte tag in constant pool”

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Every time that I run mvn clean install tomcat7:deploy in the command prompt, it fails. When I open the generated log file, it says that there is an invalid byte tag in constant pool. The file that it specifies is java/lang/CharSequence.class. Here is the log: ---- AspectJ Properties --- AspectJ Compiler 1.6.9.RC3 built on Wednesday Jun 30, 2010 at 15:46:30 GMT ---- Dump Properties --- Dump file: ajcore.20141116.131622.157.txt Dump reason: org.aspectj.apache.bcel.classfile.ClassFormatException Dump on exception: true Dump at exit condition:

专门的aop框架-AspectJ

喜你入骨 提交于 2019-12-03 08:23:06
在前面的spring的aop的使用的基础上:切面类只能写一个方法,只能增强一个功能。就需要创建多个切面对象,配置多个<aop:advisor> AspectJ的注解式开发步骤 定义一个普通的类,添加@Aspect注解,表明是一个切面类 定义要增强的方法,通过注解确定增强的类型 @Before:前置通知 @AfterReturning:后置通知 @Around:环绕通知 @AfterThrowing:异常通知 @After:最终通知(相当于java中的finally) 通过aspectj的execution表达式确定要增强的目标方法 在spring配置文件注册aspectj的自动代理 创建目标对象,创建切面对象 如果一个切面中 execution表达式需要被重复使用多次 AspectJ的通知方法中获取目标方法的数据 目标方法的参数【每一种通知都可用】 对aspectj的每一种通知类型都可以使用,在方法里面添加org.aspectj.lang.JoinPoint;参数 目标方法的返回值【后置通知可用】 环绕通知 来源: https://www.cnblogs.com/Tunan-Ki/p/11784878.html

AspectJ: How to get accessed field&#039;s value in a get() pointcut

匿名 (未验证) 提交于 2019-12-03 07:47:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing an aspect logger to write a log whenever any member variable in a given class is accessed. If I write a specific pointcut for a single variable like below, I am able to get the value of the field. @Pointcut("get(* abc.ThreadPoolService.drMaxTh)") public void drFields() {} @AfterReturning(pointcut="drFields()", returning="drMaxTh") public void afterAccessingdrFields(int drMaxTh) { LOGGER.info("Accessed the field drMaxTh " + drMaxTh); } But my class has a dozen+ variables, and I don't intend on writing specific pointcuts for each

How to re-throw exception in AspectJ around advise

Deadly 提交于 2019-12-03 07:15:55
I have some methods which throws some exception, and I want to use AspectJ around advise to calculate the execution time and if some exception is thrown and to log into error log and continue the flow by re-throwing the exception. I tried to achieve this by following but eclipse says "Unhandled Exception type". Code-against whom aspectj is to used :- public interface Iface { public void reload() throws TException; public TUser getUserFromUserId(int userId, String serverId) throws ResumeNotFoundException, TException; public TUser getUserFromUsername(String username, String serverId) throws