我需要拦截apache POI API( HSSFCell setCellValue
)的某些方法,我打算使用Spring AspectJ来满足这个要求。但是经过一些测试,我发现它不起作用。不确定是否可以像 apache POI 那样编织外部 jar?
这是我的相关代码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>
和我的aspectJ java类:
@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");
}
}
正确地,当我与 apache POI API 进行任何交互(例如调用setCellValue
on 方法HSSFCell
)时,它将打印hello world
到控制台,但在我的情况下没有发生任何事情。