I have a requirement to intercept certain method for apache POI API(HSSFCell setCellValue
), and I planed to use Spring AspectJ to fulfill this requirement. But after some testing I found it's not working. Not sure it that possible to weave the external jar like apache POI?
here is the relevant code from my pom.xml
:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.13</version>
</dependency>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<weaveDependencies>
<weaveDependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
and my aspectJ java class:
@Aspect
@Component
public class TestInterceptor
{
@Pointcut("execution(* org.apache.poi..*.*(..))")
public void methodPointcut()
{
}
@Before("methodPointcut()")
public void Interceptor(JoinPoint joinPoint)
{
System.out.println("hello world");
}
}
By right when I have any interaction with apache POI API (e.g. call the setCellValue
method on HSSFCell
), it will print hello world
to the console, but nothing happened in my case.