org.springframework.beans.factory.NoSuchBeanDefinitionException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • If you attempt to obtain an aspect from the bean context using its id it cannot be found. Example {code} <aop:config> <aop:aspect id="myadvice" ref="thingammyContextInjector"> <aop:around method="injectIntoContext" pointcut="execution(* com.scansafe.prototype.ThingammyBobFactory.createNewThing(..))"/> </aop:aspect> </aop:config> {code} I'm attempting to obtain this bean and use it as advice in conjunction with ProxyFactoryBean as follows: {code} public Object injectIntoContext(ProceedingJoinPoint pjp) throws Throwable { Object bob = pjp.proceed(); ProxyFactoryBean bean = new ProxyFactoryBean(); bean.setBeanFactory(context); bean.setTarget(bob); bean.setInterceptorNames(new String[]{"myadvice"}); return bean.getObject(); } {code} Executing this code results in an exception being thrown: {code} Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) at org.springframework.aop.framework.ProxyFactoryBean.initializeAdvisorChain(ProxyFactoryBean.java:454) at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:240) at com.scansafe.prototype.ThingammyCaptureAdvice.injectIntoContext(ThingammyCaptureAdvice.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) . . . {code}
    via by James Kavanagh,
  • If you attempt to obtain an aspect from the bean context using its id it cannot be found. Example {code} <aop:config> <aop:aspect id="myadvice" ref="thingammyContextInjector"> <aop:around method="injectIntoContext" pointcut="execution(* com.scansafe.prototype.ThingammyBobFactory.createNewThing(..))"/> </aop:aspect> </aop:config> {code} I'm attempting to obtain this bean and use it as advice in conjunction with ProxyFactoryBean as follows: {code} public Object injectIntoContext(ProceedingJoinPoint pjp) throws Throwable { Object bob = pjp.proceed(); ProxyFactoryBean bean = new ProxyFactoryBean(); bean.setBeanFactory(context); bean.setTarget(bob); bean.setInterceptorNames(new String[]{"myadvice"}); return bean.getObject(); } {code} Executing this code results in an exception being thrown: {code} Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) at org.springframework.aop.framework.ProxyFactoryBean.initializeAdvisorChain(ProxyFactoryBean.java:454) at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:240) at com.scansafe.prototype.ThingammyCaptureAdvice.injectIntoContext(ThingammyCaptureAdvice.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) . . . {code}
    via by James Kavanagh,
  • Alfresco Maven Junit test
    via Stack Overflow by caldicot
    ,
  • How do I use CommandLineJobRunner? - Spring Forum
    via by Unknown author,
  • spring3 with junit
    via by anne mishra gopi,
    • org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075) at org.springframework.aop.framework.ProxyFactoryBean.initializeAdvisorChain(ProxyFactoryBean.java:454) at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:240) at com.scansafe.prototype.ThingammyCaptureAdvice.injectIntoContext(ThingammyCaptureAdvice.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)

    Users with the same issue

    Victor_IT
    1 times, last one,
    bernardpaulus
    27 times, last one,
    odd
    42 times, last one,
    Dunmer
    128 times, last one,
    Andreas Häber
    1 times, last one,
    93 more bugmates