Spring AOP测试出现异常:no declaration can be found for element 'aop:aspectj-autoproxy'
Spring AOP测试出现异常:no declaration can be found for element 'aop:aspectj-autoproxy'.
异常信息: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'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
……
测试环境:
MyEclipse7.5
JDK1.6
JUnit4
spring-framework-2.5.6.SEC01
使用的Jar包有:spring.jar
\lib\aspect\aspectjrt.jar
\lib\aspect\aspectjweaver.jar
\lib\jakarta-commons\commons-logging.jar
\lib\j2ee\common-annotations.jar
所有的源文件文件如下:
com.yakoo5.service包下有
MyInteceptor.java
PersonService.java
com.yakoo5.service.impl包下有
PersonServiceBean.java
junit.test包下有
SpringTest.java
根目录下有beans.xml
以下是个文件源代码:
SpringTest.java
beans.xml
麻烦各位帮忙看下到底是哪里出问题了,小弟先谢了!
异常信息: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'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
……
测试环境:
MyEclipse7.5
JDK1.6
JUnit4
spring-framework-2.5.6.SEC01
使用的Jar包有:spring.jar
\lib\aspect\aspectjrt.jar
\lib\aspect\aspectjweaver.jar
\lib\jakarta-commons\commons-logging.jar
\lib\j2ee\common-annotations.jar
所有的源文件文件如下:
com.yakoo5.service包下有
MyInteceptor.java
PersonService.java
com.yakoo5.service.impl包下有
PersonServiceBean.java
junit.test包下有
SpringTest.java
根目录下有beans.xml
以下是个文件源代码:
/**
* //:MyInteceptor.java 2009-9-1 Benjamin Wu.
*/
package com.yakoo5.service;
import org.aspectj.lang.ProceedingJoinPoint;
public class MyInteceptor {
public void doBefore(){
System.out.println("前置通知");
}
public void doAfterReturning(String name){
System.out.println("后置通知:"+name);
}
public void doAfter(){
System.out.println("最终通知:");
}
public void doAfterThrowing(){
System.out.println("异常通知");
}
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("进入方法");
Object result = pjp.proceed();
System.out.println("退出方法");
return result;
}
}
/**
* //:PersonService.java 2009-9-1 Benjamin Wu.
*/
package com.yakoo5.service;
public interface PersonService {
public String getPersonName(Integer id);
public void save(String name);
public void update(String name, Integer id);
}
/**
* //:PersonServiceBean.java 2009-9-1 Benjamin Wu.
*/
package com.yakoo5.service.impl;
import com.yakoo5.service.PersonService;
public class PersonServiceBean implements PersonService {
public String getPersonName(Integer id){
return "xxx";
}
public void save(String name){
//throw new RuntimeException("我爱例外");
System.out.println("我是save()方法");
}
public void update(String name, Integer id){
System.out.println("我是update()方法");
}
}
SpringTest.java
package junit.test;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.yakoo5.service.PersonService;
import com.yakoo5.service.impl.PersonServiceBean;
public class SpringTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void aopTest() {
AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"beans.xml");
PersonService ps = (PersonServiceBean) ctx.getBean("personService");
ps.save("hello");
}
}
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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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/spring-context-2.5.xsd
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<aop:aspectj-autoproxy/>
<bean id="personService" class="com.yakoo5.service.impl.PersonServiceBean" />
<bean id="aspetBean" class="com.yakoo5.service.MyInteceptor" />
<aop:config>
<aop:aspect id="asp" ref="aspetBean">
<aop:pointcut expression="execution(* com.yakoo5.service.impl.PersonServiceBean.*(..))" id="mycut"/>
<aop:before pointcut-ref="mycut" method="doBefore"/>
</aop:aspect>
</aop:config>
</beans>
麻烦各位帮忙看下到底是哪里出问题了,小弟先谢了!
...全文
相关推荐
spring ioc aop mvc boot-学习笔记.docx
自己学习spring课程的笔记。笔记都是根据尚硅谷的课程(spring ioc,spring aop,spring mvc,spring boot等)写的。 主要内容:spring ioc,spring aop,spring mvc,spring boot
spring+element+vue开发的个人薪资确认与调整
基于spring+element+vue开发的个人薪资确认与调整,管理员导入Excel薪资信息,员工页面输入薪资查询密码查看个人季度薪资信息
Java毕业设计:后端运用Spring Boot 前端运用Vue 运用组件库Element-Ui 课程管理和评价系统
Java毕业设计:后端运用Spring Boot 前端运用Vue 运用组件库Element-Ui 课程管理和评价系统
spring-analysis
建立Spring 分析模型,结合Spring IOC 和AOP源码进行分析。
基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离的.zip
基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离的


