【问题标题】:Spring aop:configSpring AOP:配置
【发布时间】:2015-10-07 15:36:40
【问题描述】:

我是使用 Spring 框架的新手......首先出现了这个错误

The prefix aop for element aop config is not bound

然后我在 Spring.xml 中添加了以下内容

<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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

现在还是有错误

Error occured processing XML 'org/springframework/aop/aspectj/AspectJMethodBeforeAdvice'

这是我完整的 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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <aop:config>
        <aop:aspect ref="audience">
            <aop:before pointcut="execution(* com.uttara.spring.Performer.perform(..))"
                method="takeSeats" />
            <aop:before pointcut="execution(* com.uttara.spring.Performer.perform(..))"
                method="switchOffPhones" />
            <aop:after-returning
                pointcut="execution(* com.uttara.spring.Performer.perform(..))"
                method="clap" />
            <aop:after-throwing
                pointcut="execution(* com.uttara.spring.Performer.perform(..))"
                method="boo" />
        </aop:aspect>
    </aop:config>

    <bean id="duke" class="com.uttara.spring.Juggler">
        <constructor-arg value="15"></constructor-arg>
    </bean>
    <bean id="poem" class="com.uttara.spring.EnglishPoem"></bean>
    <bean id="hans" class="com.uttara.spring.PoeticJuggler">
        <constructor-arg value="15"></constructor-arg>
        <constructor-arg ref="poem"></constructor-arg>
    </bean>
    <bean id="audience" class="com.uttara.spring.Audience"></bean>
</beans>

请帮忙! 我完全没有头绪。 我有一些库文件。我不知道他们到底在做什么。缺少图书馆吗?是什么导致了这些错误?我该如何解决?

【问题讨论】:

  • 如果您是 Spring 新手,请不要从旧的 XML 配置开始。使用 Spring Boot,并使用 start.spring.io 自动生成一个完整的现成包以供使用。

标签: java xml spring aop


【解决方案1】:

使用spring需要大量的库文件。 AspectjrtAspectj-weaveraop-alliance 是一些,我们没有作为 spring 依赖 jar 文件获得。我们已经下载并添加到类路径以成功运行基于 Spring 的应用程序。

【讨论】:

    【解决方案2】:

    (...) 为切入点指定参数(零个或多个)的方式不正确。尝试在切入点表达式中替换为(..)

    【讨论】:

      猜你喜欢
      • 2011-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 2012-11-05
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多