【问题标题】:AspectJ pointcut expression for Jackson DeserializationContext reportMappingExceptionJackson DeserializationContext reportMappingException 的 AspectJ 切入点表达式
【发布时间】:2017-03-15 13:02:43
【问题描述】:

我正在尝试编写一个切入点来获得周围的建议: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

试验一:

@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>

【问题讨论】:

  • Minimal, Complete, and Verifiable example 怎么样?例如,我没有看到您的ContactManagerLogger,也没有看到调用杰克逊的代码。 POM 也不完整。你使用正确的杰克逊版本吗?要拦截的方法只有2.8以后才有。这么多变数,我不喜欢胡思乱想。

标签: jackson aspectj aspectj-maven-plugin


【解决方案1】:

您是否尝试过配置 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

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

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 2022-01-06
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多