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个回答

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

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

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐