java错误-The prefix "aop" for element "aop:aspectj-autoproxy" is not bound.

配置springmvc的aop时出错:

当我向配置文件中添加:<aop:aspectj-autoproxy proxy-target-class="true"/> 时出错:

The prefix "aop" for element "aop:aspectj-autoproxy" is not bound.

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [springmvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The prefix "aop" for element "aop:aspectj-autoproxy" is not bound.

解决方法:

添加这些有关AOP的配置:

添加后如下面所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
阅读更多

Spring AOP测试出现异常:no declaration can be found for element 'aop:aspectj-autoproxy'

09-08

[b][color=#FF0000]Spring AOP测试出现异常:no declaration can be found for element 'aop:aspectj-autoproxy'[/color].[/b]rnrn[b]异常信息:[/b]org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from class path resource [beans.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:aspectj-autoproxy'.rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)rn at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)rn……rnrn[b]测试环境:[/b]rnMyEclipse7.5rnJDK1.6rnJUnit4rnspring-framework-2.5.6.SEC01rn使用的Jar包有:spring.jarrn\lib\aspect\aspectjrt.jarrn\lib\aspect\aspectjweaver.jarrn\lib\jakarta-commons\commons-logging.jarrn\lib\j2ee\common-annotations.jarrnrn所有的源文件文件如下:rncom.yakoo5.service包下有rn MyInteceptor.javarn PersonService.javarnrncom.yakoo5.service.impl包下有rn PersonServiceBean.javarnrnjunit.test包下有rn SpringTest.javarnrn根目录下有beans.xmlrnrn以下是个文件源代码:rn[code=Java]rn/**rn * //:MyInteceptor.java 2009-9-1 Benjamin Wu.rn */rnpackage com.yakoo5.service;rnrnimport org.aspectj.lang.ProceedingJoinPoint;rnrnpublic class MyInteceptor rn rn public void doBefore()rn System.out.println("前置通知");rn rn rn public void doAfterReturning(String name)rn System.out.println("后置通知:"+name);rn rnrn public void doAfter()rn System.out.println("最终通知:");rn rnrn public void doAfterThrowing()rn System.out.println("异常通知");rn rn rn public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwablern System.out.println("进入方法");rn Object result = pjp.proceed();rn System.out.println("退出方法");rn return result;rn rnrnrn[/code]rnrn[code=Java]rn/**rn * //:PersonService.java 2009-9-1 Benjamin Wu.rn */rnpackage com.yakoo5.service;rnrnpublic interface PersonService rnrn public String getPersonName(Integer id);rnrn public void save(String name);rnrn public void update(String name, Integer id);rnrnrn[/code]rn[code=Java]rn/**rn * //:PersonServiceBean.java 2009-9-1 Benjamin Wu.rn */rnpackage com.yakoo5.service.impl;rnrnimport com.yakoo5.service.PersonService;rnrnpublic class PersonServiceBean implements PersonService rn public String getPersonName(Integer id)rn return "xxx";rn rn rn public void save(String name)rn //throw new RuntimeException("我爱例外");rn System.out.println("我是save()方法");rn rnrn public void update(String name, Integer id)rn System.out.println("我是update()方法");rn rnrnrn[/code]rnrnSpringTest.javarn[code=Java]rnpackage junit.test;rnrnimport org.junit.BeforeClass;rnimport org.junit.Test;rnimport org.springframework.context.support.AbstractXmlApplicationContext;rnimport org.springframework.context.support.ClassPathXmlApplicationContext;rnrnimport com.yakoo5.service.PersonService;rnimport com.yakoo5.service.impl.PersonServiceBean;rnrnpublic class SpringTest rnrn @BeforeClassrn public static void setUpBeforeClass() throws Exception rn rnrn @Testrn public void aopTest() rn AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext(rn "beans.xml");rn PersonService ps = (PersonServiceBean) ctx.getBean("personService");rn ps.save("hello");rn rnrnrnrn[/code]rnrnbeans.xmlrn[code=XML]rnrnrnrn rn rn rn rn rn rn rn rn rn rnrn[/code]rnrn麻烦各位帮忙看下到底是哪里出问题了,小弟先谢了!rnrn

没有更多推荐了,返回首页