spring使用AOP时the prefix aop for element is not bound.和no declaration can be found错误

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012817635/article/details/51149329

在使用<aop:config>标签时,xml编译错误报:the prefix aop for element "aop:config" is not bound错误

原因是:未在xml文件头部导入xmlns:aop=“http://www.springframework.org/schema/aop”


导入后出现继续出现编译错误no declaration can be found

原因是:未在xml头文件中导入 xsi:schemaLocation="http://www.springframework.org/schema/aop"

展开阅读全文

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 论坛

Spring 使用 AOP 出现错误

03-11

最近在学习Spring的AOP(马士兵的Spring)rn在照着视屏做的同时,出现了一个无法解决的错误rn下边我把我的错误代码贴出来rn请各位帮忙rnbeans.xmlrn[code=XML]rnrnrn rn rn rn[/code]rnrnLogInterceptor.javarn[code=Java]package com.chk.aop;rnrnimport org.aspectj.lang.annotation.Aspect;rnimport org.aspectj.lang.annotation.Before;rnimport org.springframework.stereotype.Component;rnrn@Aspectrn@Componentrnpublic class LogInterceptor rn @Before("execution(public void com.chk.impl.UserDAOImpl.save(com.chk.model.User))")rn public void before() rn System.out.println("Method Start!");rn rnrn[/code]rnrnUserTest.javarn[code=Java]package com.chk.model;rnrnimport org.junit.Test;rnimport org.springframework.context.ApplicationContext;rnimport org.springframework.context.support.ClassPathXmlApplicationContext;rnrnimport com.chk.service.UserService;rnrnpublic class UserTest rnrn @Testrn public void test() throws Exception rn ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");rnrn UserService service = (UserService) ctx.getBean("userService");rnrn service.add(new User());rn rnrnrn[/code]rnrn错误提示rn[code=XML]org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptorrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)rn at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:728)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at com.chk.model.UserTest.test(UserTest.java:13)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:601)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)rn at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:236)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptorrn at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)rn at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)rn ... 35 morernCaused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptorrn at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry.(DefaultAdvisorAdapterRegistry.java:49)rn at org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry.(GlobalAdvisorAdapterRegistry.java:31)rn at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.(AbstractAutoProxyCreator.java:118)rn at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.(AbstractAdvisorAutoProxyCreator.java:47)rn at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.(AspectJAwareAdvisorAutoProxyCreator.java:46)rn at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.(AnnotationAwareAspectJAutoProxyCreator.java:48)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)rn at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)rn at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:525)rn at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)rn ... 37 morernCaused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptorrn at java.net.URLClassLoader$1.run(URLClassLoader.java:366)rn at java.net.URLClassLoader$1.run(URLClassLoader.java:355)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:354)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:423)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:356)rn ... 48 morernrn[/code]rnrn这次没有和Hibernate结合,所以没有jar包的冲突,该加的包都加了rn但是问题就是得不到解决rnrn麻烦各位了rn 论坛

springaop错误

09-02

我用的是spring2.5开发的aop,可是做拦截的时候报错,代码如下:rnpackage cn.itcast.service;rnrnimport org.aspectj.lang.annotation.Aspect;rnimport org.aspectj.lang.annotation.Before;rnimport org.aspectj.lang.annotation.Pointcut;rnrn/**rn * rn * 切面rn *rn */rn@Aspectrnpublic class MyInterceptor rn @Pointcut("execution (* cn.itcast.service.impl.PersonServiceBean.*(..))")rn private void anyMethod() rn rn @Before("anyMethod()")rn public void doAccessCheck()rn System.out.println("前置通知");rn rnrnrnrnpackage cn.itcast.service;rnrnpublic interface PersonService rn public void save(String name);rn public void update(String name,Integer id);rn public String getPersonName(Integer id);rnrnrnpackage cn.itcast.service.impl;rnrnimport cn.itcast.service.PersonService;rnrnpublic class PersonServiceBean implements PersonService rnrn public void save(String name) rn System.out.println("我是save()方法");rn rnrn public void update(String name, Integer id) rn System.out.println("我是update()方法");rn rnrn public String getPersonName(Integer id) rn System.out.println("我是 getPersonName()方法");rn return "xxxx";rn rnrnrnrnpackage junit.test;rnrnimport org.junit.BeforeClass;rnimport org.junit.Test;rnimport org.springframework.context.ApplicationContext;rnimport org.springframework.context.support.ClassPathXmlApplicationContext;rnrnimport cn.itcast.service.PersonService;rnrnpublic class SpringAOPTest rnrn @BeforeClassrn public static void setUpBeforeClass() throws Exception rn rnrn @Test public void interceptorTest()rn ApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");rn PersonService personService = (PersonService)cxt.getBean("personService");rn personService.save("xxxxx");rn rnrnrnrnrnrnrn rn rn rnrnrn错误信息如下:rnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut anyMethodrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)rn at java.security.AccessController.doPrivileged(Native Method)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)rn at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)rn at junit.test.SpringAOPTest.interceptorTest(SpringAOPTest.java:17)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)rn at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)rn at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)rn at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)rn at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:300)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)rnCaused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut anyMethodrn at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:317)rn at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:206)rn at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)rn at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:174)rn at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:195)rn at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:250)rn at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:284)rn at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:113)rn at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)rn at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)rn at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)rn at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:325)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1344)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)rn ... 38 morern 论坛

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