AspectJ切换表达式用于Jackson DeserializationContext reportMappingException

时间:2017-03-15 13:02:44

标签: jackson aspectj aspectj-maven-plugin

我正在尝试编写一个切入点来围绕:com.fasterxml.jackson.databind.DeserializationContext.reportMappingException()方法。

这是我到目前为止所做的事情,而且它不起作用,即maven抱怨:

[WARNING] advice defined in com.charter.aesd.videocatalog.client.interceptor.ContactManagerLogger has not been applied [Xlint:adviceDidNotMatch]
    /Users/rhasija/dev/projects/video/videocatalog-middle/client/src/main/java/com/charter/aesd/videocatalog/client/interceptor/ContactManagerLogger.java:36

试验1:

@Pointcut("execution(* com.fasterxml.jackson.databind.DeserializationContext+.*(..))")
public void servicePointcut() {}

试验2:

@Pointcut("execution( * com.fasterxml.jackson.databind.*.*(..) )")
public void servicePointcut() {}

下面是我的pom.xml。是不是可以通过AspectJ对外部库进行切入点?

<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
    </dependency>
    ....
</dependencies>

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.10</version>
    <configuration>
        <complianceLevel>1.8</complianceLevel>
        <source>1.8</source>
        <target>1.8</target>
        <includes>
            <include>**/*.java</include>
            <include>**/*.groovy</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <!--suppress MavenModelInspection -->
                <goal>compile</goal>
                <!--suppress MavenModelInspection -->
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>info.ponge.julien.hacks.guiceaspectj.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <!--suppress MavenModelInspection -->
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

1 个答案:

答案 0 :(得分:0)

您是否尝试过配置maven插件?添加:

<configuration>

  ....

  <weaveDependencies>
    <weaveDependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </weaveDependency>
  <weaveDependencies>
<configuration>

Weaving already compiled JAR artifacts

weaveDependencies对应ajc -inpath,请记住它的作用是获取jar文件中的类,将它们展开,然后将它们包含在输出target/classes中。

The AspectJ compiler/weaver

Maven aspectj:compile

您也可以使用加载时编织,在类加载期间将方面指令注入字节代码。