2

好吧,我已经通过 XML 文件成功地完成了 AOP,但我正在努力使用 AspectJ。出于某种原因,我无法让它正常工作。我在网上看了,我发现的任何东西似乎都不起作用,不知道为什么。

这是我的代码

方面J.java:

@Aspect
public class AspectJ {

@Before("execution(* com.ibm..AnimalBean.*(..) )" )
public void logBefore(JoinPoint joinpoint) throws Throwable {
    System.out.println("AspectJ - Before " +     
joinpoint.getSignature().getName() );
}
}

TestClass (.java.): public class TestClass { AnimalBean testBean;

@Autowired
public void setTestBean(AnimalBean testBean) {
    this.testBean = testBean;
}

public void runTestClass(int id, String animal) {
    ApplicationContext jdbcContext = new 
ClassPathXmlApplicationContext("jdbcContext.xml");
    AnimalDaoImpl animalDao = (AnimalDaoImpl)
jdbcContext.getBean("animalDaoImpl"); 

    testBean.setId(id);
    testBean.setTestAnimal(animal);
    System.out.println("setBean - id: "+testBean.getId()+" animal:
"+testBean.getTestAnimal());
    animalDao.createRow(testBean);
    testBean = new AnimalBean();
    this.testBean = animalDao.retrieveRow(testBean, 2);
    System.out.println("getBean - id: "+testBean.getId()+" animal:
"+testBean.getTestAnimal());
}
}

appContext.xml:

    <aop:aspectj-autoproxy />`
    <bean id="myAnimalBean" class="com.ztp.spring.injection.AnimalBean" />
     <bean id="myAnimalBean" class="com.ztp.spring.injection.AnimalBean" /> <-- error
    <bean id="myTestClass" class="com.ztp.spring.injection.TestClass"> <--error
    <property name="testBean" ref="myAnimalBean" />
</bean>
<bean id="myAspectJ" class="com.ibm.spring.aspect.AspectJ" />

其中 *** 出现错误,显示“构建路径不完整。找不到 org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException 的类文件”

我也有三个方面的 jar 文件;aspectjrt-1.5.4.java,aspectjtools-1.6.1.java,aspectjweaver-1.7.0.java。

我在这里遗漏了一些明显的东西吗?或者它是不是很明显?如果之前已经回答过,请通知我,我很想最终解决这个问题。

提前致谢。

编辑:我忘了提,我在“找不到 org.aspectj.weaver.reflect.ReflectionWorld ”看到了帖子,他们从发行版“ http://dist.spring ”安装了 AspectJ

所以我想问题是,我该如何安装 AspectJ?如果您愿意,请回答,我将尝试使用 Google。

已解决!!!!!!:我解决了这个问题,我会在这里回答,所以这篇文章可以帮助其他和我一样迷失的人。安装Eclipse软件的时候,输入地址“ http://download.eclipse.org/tools/ajdt/35/update ”,就是AspectJ的全部代码。

4

0 回答 0