aspectj

How to test an aspect with SpringBootTest?

夙愿已清 提交于 2019-12-05 02:15:29
问题 I created a simple aspect in Spring using Spring Boot 2.1.6.RELEASE. It basically logs the total time spent on a method. @Aspect @Component public class TimeLoggerAspect { private static final Logger log = LoggerFactory.getLogger(TimeLoggerAspect.class); @Around("@annotation(demo.TimeLogger)") public Object methodTimeLogger(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long totalTime = System

Disabling certain aspects during unit test runs

只谈情不闲聊 提交于 2019-12-04 22:56:06
I have integration tests (load context) and unit tests running together. My code does aspectj compile time weaving using spring. My problem is that my declared advises also run during some of my unit tests. This kills the notion of a unit test, which is why I would like to disable them. Is there something I can put on the pointcut declaration, some method I can call, some spring configuration, or maven command that disables these advises for something like all *UnitTest.java? Thanks for the help. example: I have the following unit test: @RunWith(MockitoJUnitRunner.class) public class

AspectJ Maven Plugin cannot compile my project

倾然丶 夕夏残阳落幕 提交于 2019-12-04 22:49:45
I try to use aspectj maven plugin for compile project with aspectj compiler and then I try to package classes into "war" file. Unfortunately, it doesn't work with following configuration (pom.xml): <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>com.liferay.maven.plugins</groupId> <artifactId>liferay-maven-plugin</artifactId> <version>${liferay.maven.plugin.version}</version> <executions> <execution> <phase

spring

给你一囗甜甜゛ 提交于 2019-12-04 20:35:22
什么是 Spring 框架? Spring 是一种轻量级开发框架,旨在提高开发人员的开发效率以及系统的可维护性。Spring 官网:https://spring.io/。 我们一般说 Spring 框架指的都是 Spring Framework,它是很多模块的集合,使用这些模块可以很方便地协助我们进行开发。这些模块是:核心容器、数据访问/集成,、Web、AOP(面向切面编程)、工具、消息和测试模块。比如:Core Container 中的 Core 组件是Spring 所有组件的核心,Beans 组件和 Context 组件是实现IOC和依赖注入的基础,AOP组件用来实现面向切面编程。 Spring 官网列出的 Spring 的 6 个特征: 核心技术 :依赖注入(DI),AOP,事件(events),资源,i18n,验证,数据绑定,类型转换,SpEL。 测试 :模拟对象,TestContext框架,Spring MVC 测试,WebTestClient。 数据访问 :事务,DAO支持,JDBC,ORM,编组XML。 Web支持 : Spring MVC和Spring WebFlux Web框架。 集成 :远程处理,JMS,JCA,JMX,电子邮件,任务,调度,缓存。 语言 :Kotlin,Groovy,动态语言。 列举一些重要的Spring模块? 下图对应的是 Spring4.x

AspectJ not capture calls from jar file

我的梦境 提交于 2019-12-04 19:42:41
I want to do specific action when System.currentTimeMillis() is called. I use AspectJ as below to do that. public aspect CurrentTimeInMillisMethodCallChanger { long around(): call(public static native long java.lang.System.currentTimeMillis()) { //provide my own implementation } } This program works fine when System.currentTimeMillis() is called in any method of the application. However, when System.currentTimeMillis() is called from method inside a jar file then around is not executed. I used within(packageofJarFile.*) , but it does not work. I am using Eclipse. Please let me know what I need

Lombok and AspectJ

不问归期 提交于 2019-12-04 18:46:49
问题 Im trying to use Lombok in combination with AspectJ and Maven. So, what's the problem? When i use the AspectJ Maven Plugin (www.mojohaus.org/aspectj-maven-plugin/), it takes the sources and compiles them and ignores changes made by Lombok. I followed this tutorial and came up with this code and AspectJ works, but Lombok dies with this message: [WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled. Your processor is: org.aspectj.org.eclipse

How to intercept method which handles its own exceptions using AspectJ

你。 提交于 2019-12-04 17:32:55
I'm trying add some monitoring when some specific exception occurs. For example, if I have an aspect like this: @Aspect public class LogAspect { @AfterThrowing(value = "execution(* *(..))", throwing = "e") public void log(JoinPoint joinPoint, Throwable e){ System.out.println("Some logging stuff"); } } And test class: public class Example { public void divideByZeroWithCatch(){ try{ int a = 5/0; } catch (ArithmeticException e){ System.out.println("Can not divide by zero"); } } public void divideByZeroWithNoCatch(){ int b = 5/0; } public static void main (String [] args){ Example e = new Example(

AspectJ - Retrieve list of annotated parameters

霸气de小男生 提交于 2019-12-04 17:23:05
From the following previous question ( AspectJ - Presence of annotation in join point expression not recognized ), My goal: In an aspect, i'd like to be able to extract/retrieve all annotated parameters from matching functions, no matter how many there are. (and then apply some treatment on but it's not the scope of this question) So for the moment, this is what i did (not working): @Before("execution (* org.xx.xx.xx..*.*(@org.xx.xx.xx.xx.xx.Standardized (*),..))") public void standardize(JoinPoint jp) throws Throwable { Object[] myArgs = jp.getArgs(); getLogger().info("Here: arg length=" +

Does a set() field pointcut get invoked if field is set via reflection?

喜夏-厌秋 提交于 2019-12-04 17:13:12
I have a field set pointcut, which seems to do as I expect. Its defined as follows before(Object newval): set(@Serviced private * *.*) && args(newval) The above is meant to capture: whenever a private field attribute, annotated with @Serviced, is set call my before advice. Everything seems to work fine, except for the one case in my code that sets a variable matching the above via java reflection ( ie via java.lang.reflect.Field.set(....). Any idea's how I can catch that "set" also? Thanks As you have noticed, the set() pointcut cannot intercept reflective field changes. But if you control (i

AspectJ with weblogic

左心房为你撑大大i 提交于 2019-12-04 17:01:19
I am trying to run AspectJ on Weblogic with LTW. My pointcut is for public constructor and methods, and advices are for Before, AfterReturning and AfterThrowing. I am getting following error when I access a simple "Hello World" jsp: javax.servlet.ServletException: Servlet class: 'jsp_servlet.__index' doesn't have a default constructor at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:315) at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:288) at weblogic.security.acl.internal.AuthenticatedSubject.doAs