26.12.2015, 23:57. Показов 1211. Ответов 2
Здравствуйте. Создал Spring AOP приложение по примеру из книги, не пойму в чем ошибка при запуске.
Ошибка:
Cannot create inner bean '(inner bean)#1877ab81' of type [org.springframework.aop.aspectj.AspectJM ethodBeforeAdvice] while setting constructor argument
|
Кликните здесь для просмотра всего текста
"
дек 26, 2015 10:37:03 PM org.springframework.context.support.Clas sPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.Clas sPathXmlApplicationContext@306a30c7: startup date [Sat Dec 26 22:37:03 EET 2015]; root of context hierarchy
дек 26, 2015 10:37:03 PM org.springframework.beans.factory.xml.Xm lBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [resources/knights-aop.xml]
дек 26, 2015 10:37:04 PM org.springframework.context.support.Clas sPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'knight' defined in class path resource [resources/knights-aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJ PointcutAdvisor#0': Cannot create inner bean '(inner bean)#1877ab81' of type [org.springframework.aop.aspectj.AspectJM ethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name '(inner bean)#1877ab81': Cannot resolve reference to bean 'embark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'embark': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
Exception in thread "main" org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'knight' defined in class path resource [resources/knights-aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJ PointcutAdvisor#0': Cannot create inner bean '(inner bean)#1877ab81' of type [org.springframework.aop.aspectj.AspectJM ethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name '(inner bean)#1877ab81': Cannot resolve reference to bean 'embark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'embark': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBean(AbstractAutowireCapableBeanFacto ry.java:478)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory$1.getObject(Abstra ctBeanFactory.java:306)
at org.springframework.beans.factory.suppor t.DefaultSingletonBeanRegistry.getSingle ton(DefaultSingletonBeanRegistry.java:23 0)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.doGetBean(Abstract BeanFactory.java:302)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.getBean(AbstractBe anFactory.java:197)
at org.springframework.beans.factory.suppor t.DefaultListableBeanFactory.preInstanti ateSingletons(DefaultListableBeanFactory .java:772)
at org.springframework.context.support.Abst ractApplicationContext.finishBeanFactory Initialization(AbstractApplicationContex t.java:839)
at org.springframework.context.support.Abst ractApplicationContext.refresh(AbstractA pplicationContext.java:538)
at org.springframework.context.support.Clas sPathXmlApplicationContext.<init>(ClassP athXmlApplicationContext.java:139)
at org.springframework.context.support.Clas sPathXmlApplicationContext.<init>(ClassP athXmlApplicationContext.java:83)
at knights.KnightAopMain.main(KnightAopMain .java:9)
at sun.reflect.NativeMethodAccessorImpl.inv oke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.inv oke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl .invoke(DelegatingMethodAccessorImpl.jav a:43)
at java.lang.reflect.Method.invoke(Method.j ava:497)
at com.intellij.rt.execution.application.Ap pMain.main(AppMain.java:144)
Caused by: org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJ PointcutAdvisor#0': Cannot create inner bean '(inner bean)#1877ab81' of type [org.springframework.aop.aspectj.AspectJM ethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name '(inner bean)#1877ab81': Cannot resolve reference to bean 'embark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'embark': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveInn erBean(BeanDefinitionValueResolver.java: 313)
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveVal ueIfNecessary(BeanDefinitionValueResolve r.java:129)
at org.springframework.beans.factory.suppor t.ConstructorResolver.resolveConstructor Arguments(ConstructorResolver.java:648)
at org.springframework.beans.factory.suppor t.ConstructorResolver.autowireConstructo r(ConstructorResolver.java:140)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.aut owireConstructor(AbstractAutowireCapable BeanFactory.java:1143)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBeanInstance(AbstractAutowireCapableB eanFactory.java:1046)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.doC reateBean(AbstractAutowireCapableBeanFac tory.java:510)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBean(AbstractAutowireCapableBeanFacto ry.java:482)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory$1.getObject(Abstra ctBeanFactory.java:306)
at org.springframework.beans.factory.suppor t.DefaultSingletonBeanRegistry.getSingle ton(DefaultSingletonBeanRegistry.java:23 0)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.doGetBean(Abstract BeanFactory.java:302)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.getBean(AbstractBe anFactory.java:202)
at org.springframework.aop.framework.autopr oxy.BeanFactoryAdvisorRetrievalHelper.fi ndAdvisorBeans(BeanFactoryAdvisorRetriev alHelper.java:92)
at org.springframework.aop.framework.autopr oxy.AbstractAdvisorAutoProxyCreator.find CandidateAdvisors(AbstractAdvisorAutoPro xyCreator.java:101)
at org.springframework.aop.aspectj.autoprox y.AspectJAwareAdvisorAutoProxyCreator.sh ouldSkip(AspectJAwareAdvisorAutoProxyCre ator.java:103)
at org.springframework.aop.framework.autopr oxy.AbstractAutoProxyCreator.postProcess BeforeInstantiation(AbstractAutoProxyCre ator.java:248)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.app lyBeanPostProcessorsBeforeInstantiation( AbstractAutowireCapableBeanFactory.java: 988)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.res olveBeforeInstantiation(AbstractAutowire CapableBeanFactory.java:959)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBean(AbstractAutowireCapableBeanFacto ry.java:472)
... 15 more
Caused by: org.springframework.beans.factory.BeanCr eationException: Error creating bean with name '(inner bean)#1877ab81': Cannot resolve reference to bean 'embark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'embark': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveRef erence(BeanDefinitionValueResolver.java: 359)
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveVal ueIfNecessary(BeanDefinitionValueResolve r.java:108)
at org.springframework.beans.factory.suppor t.ConstructorResolver.resolveConstructor Arguments(ConstructorResolver.java:634)
at org.springframework.beans.factory.suppor t.ConstructorResolver.autowireConstructo r(ConstructorResolver.java:140)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.aut owireConstructor(AbstractAutowireCapable BeanFactory.java:1143)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBeanInstance(AbstractAutowireCapableB eanFactory.java:1046)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.doC reateBean(AbstractAutowireCapableBeanFac tory.java:510)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBean(AbstractAutowireCapableBeanFacto ry.java:482)
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveInn erBean(BeanDefinitionValueResolver.java: 299)
... 33 more
Caused by: org.springframework.beans.factory.BeanCr eationException: Error creating bean with name 'embark': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.ins tantiateBean(AbstractAutowireCapableBean Factory.java:1105)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBeanInstance(AbstractAutowireCapableB eanFactory.java:1050)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.doC reateBean(AbstractAutowireCapableBeanFac tory.java:510)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.cre ateBean(AbstractAutowireCapableBeanFacto ry.java:482)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.doGetBean(Abstract BeanFactory.java:325)
at org.springframework.beans.factory.suppor t.AbstractBeanFactory.getBean(AbstractBe anFactory.java:197)
at org.springframework.beans.factory.suppor t.BeanDefinitionValueResolver.resolveRef erence(BeanDefinitionValueResolver.java: 351)
... 41 more
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at java.lang.Class.getDeclaredConstructors0 (Native Method)
at java.lang.Class.privateGetDeclaredConstr uctors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.ja va:3075)
at java.lang.Class.getDeclaredConstructor(C lass.java:2178)
at org.springframework.beans.factory.suppor t.SimpleInstantiationStrategy.instantiat e(SimpleInstantiationStrategy.java:80)
at org.springframework.beans.factory.suppor t.AbstractAutowireCapableBeanFactory.ins tantiateBean(AbstractAutowireCapableBean Factory.java:1098)
... 47 more
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWor ld$ReflectionWorldException
at java.net.URLClassLoader.findClass(URLCla ssLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoa der.java:424)
at sun.misc.Launcher$AppClassLoader.loadCla ss(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoa der.java:357)
... 53 more
Process finished with exit code 1
|
Конфигурация:
| XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| <?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url]http://www.springframework.org/schema/beans/spring-beans-3.0.xsd[/url]
[url]http://www.springframework.org/schema/aop[/url]
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="knight" class="knights.BraveKnight">
<constructor-arg ref="quest" />
</bean>
<bean id="quest" class="knights.SlayDragonQuest" />
<bean id="minstrel" class="knights.Minstrel" />
<aop:config>
<aop:aspect ref="minstrel">
<aop:pointcut id="embark" expression="execution(* *.embarkOnQuest(..))" />
<aop:before pointcut-ref="embark" method="singBeforeQuest"/>
<aop:after pointcut-ref="embark" method="singAfterQuest"/>
</aop:aspect>
</aop:config>
</beans> |
|
Точка входа:
| Java |
1
2
3
4
5
6
7
| public class KnightAopMain {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("resources/knights-aop.xml");
Knight knight = (Knight) context.getBean("knight");
knight.embarkOnQuest();
}
} |
|
Добавлено через 15 минут
Правильный ответ:
добавить в проект AspectJ: файлы aspectjrt.jar и aspectjweaver.jar