【问题标题】:AOP in spring aspect warning春季方面警告中的 AOP
【发布时间】:2012-12-06 16:39:49
【问题描述】:

我从 Spring 框架 3.1.2 开始学习 AOP。但我有麻烦。在Beans.xml 上下文文件中我写道:

<?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: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/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">

    <bean id = "audience" class="com.MySpring.Audience"></bean>

    <aop:config>
        <aop:aspect ref="audience">
            <aop:pointcut id="performance" expression="execution(* com.MySpring.Performer.perform(..))"/>

            <aop:before pointcut-ref="performance" method="seatDown"/>
            <aop:before pointcut-ref="performance" method="turnOffPhone"/>
            <aop:after-returning pointcut-ref="performance" method="applauz"/>
            <aop:after-throwing pointcut-ref="performance" method="demandRefund"/>

        </aop:aspect>
    </aop:config>

</beans>

还有Java类

public class AOPTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ApplicationContext context = new ClassPathXmlApplicationContext(
                "Beans.xml");

    }

}

// ///
class Audience {

    public void seatDown() {
        out.println("Seat down");
    }

    public void turnOffPhone() {
        out.println("Turn Off Phone");

    }

    public void applauz() {

        out.println("Aplauz");
    }

    public void demandRefund() {
        out.println("We have money back");
    }

}
////
interface Performer{
    void perform();
}

但在错误控制台中我看到:

Description Resource Path Location Type Error occured processing XML 'class path resource [org/aopalliance/aop/Advice.class] cannot be opened because it does not exist'. See Error Log for more details Beans.xml /AnnotationsWiring/src line 11 Spring Beans Problem 第二个错误:

Description Resource Path Location Type Error occured processing XML 'org/springframework/aop/aspectj/AspectJMethodBeforeAdvice'. See Error Log for more details Beans.xml /AOP/src line 12 Spring Beans Problem

【问题讨论】:

  • 你的类路径中是否有所需的罐子?
  • 当然我的classpath里都有spring jar。
  • 这个类不是 Spring 的一部分。你需要 aopalliance.jar,sourceforge.net/projects/aopalliance/files
  • 我下载了这个但是我编译错误Caused by: java.lang.ClassNotFoundException: org.aopalliance.aop.Advice
  • 我推荐使用 Maven 或 Gradle,这样你就不会陷入依赖地狱。

标签: java xml spring aop


【解决方案1】:

我猜你正在使用 spring in action 中的示例来学习 spring。实际上,您缺少一个 com.springsource.org.apoalliance.jar 文件,该文件未包含在 org.springframework.aop.jar 中(虽然我不知道为什么)。

下载地址:http://sourceforge.net/projects/aopalliance/files/aopalliance/

您拥有Caused by: java.lang.ClassNotFoundException: org.aopalliance.aop.Advice,因为您没有将 jar 包含到您的类路径中。

【讨论】:

    猜你喜欢
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    相关资源
    最近更新 更多