tmh7788
tmh7788
2010-10-05 12:32

Spring初学者配置AOP总是错误Unable to locate Spring NamespaceHandler for XML schema namesp

已采纳

源码:

package stu.liuli.aspect;

public interface ArithmeticCalculator {
void add(int i,int j);
}

package stu.liuli.aspect;

import org.springframework.stereotype.Component;

@Component("arithmeticCalculator")
public class ArithmeticCalculatorImp implements ArithmeticCalculator {

@Override
public void add(int i, int j) {
    int result = i + j ;
    System.out.println("add :" + result);
}

}

package stu.liuli.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {
@Before(value = "excution(* stu.liuli.aspect.*.*(..)")
public void beforeMethodLogging(){
System.out.println("before method...");
}
}

XML文件:
<?xml version="1.0" encoding="UTF-8"?>
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"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

aop:aspectj-autoproxy/

/context:component-scan

jar包:用MyEclipse的Spring支持导入了Spring 2.5 Core Librarier,然后自己导入了aspectjrt.jar,aspectjweaver.jar,cglib-nodep-2.1_3.jar

然后运行时候总是报异常:Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/aop]
Offending resource: class path resource [applicationContext.xml]

我也去网上找了相关的解决方法好像都不行。。。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • freshman_2007 屌丝哥 11年前

    1、在applicantContext.xml中添加如下语句:
    试试看。

    2、检查JAR包,看是否有冲突。

    点赞 评论 复制链接分享
  • weixin_42528782 我叫刘十四 8年前

    我也遇到了这样的问题,网上那些人都瞎叫唤。没有一个可以解决的。你是怎么解决的啊?

    点赞 评论 复制链接分享