1

我根本无法让 AspectJ 工作,并且在学习了 10 个不同的教程之后,我已经没有想法了。

这就是我想要做的......

我有一个 Spring 应用程序。它使用 Spring、Perf4J 和 Now Aspect(如果它可以工作的话!),我想在我的公共方法的 tog 中使用 @Profiled("some tag here")。就是这样,没什么太花哨的。

这是我要运行的代码:

@Override
@Profiled(tag = "MainClass" + ".runMethod", logFailuresSeparately = true)
public Collection<Throwable> runMethod() throws Exception {

    System.out.println("Running a simple method that I want timings for.");

}

这是我在 Maven 中使用的 POM 依赖项,用于设置所有内容。

<dependencies>
    <!-- Spring (includes spring-aop)-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- AspectJ (required spring-aop dependency) -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.5</version>
    </dependency>
    <!-- LOG -->
    <dependency>
        <groupId>org.perf4j</groupId>
        <artifactId>perf4j</artifactId>
        <version>${perf4j.version}</version>
    </dependency>
</dependencies>

这是方面 bean 文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:aop="http://www.springframework.org/schema/aop"

   xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<aop:aspectj-autoproxy proxy-target-class="true">
    <aop:include name="timingAspect"/>
</aop:aspectj-autoproxy>

<!--<context:load-time-weaver/> -->

<!--  The perf4j aspect -->
<bean id="timingAspect" class="org.perf4j.log4j.aop.TimingAspect"/>

这是我将 XML beans 文件带入(在 spring 应用程序上下文文件中)的方式:

<import resource="aspectBeans.xml" />

现在,应用程序编译、运行并打印了我的 System.out.println 行,但我完全没有看到与时间相关的任何内容。

4

0 回答 0