org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined

Spring JIRA | James Kavanagh | 4 years ago
  1. 0

    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}

    Spring JIRA | 4 years ago | James Kavanagh
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined
  2. 0

    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}

    Spring JIRA | 4 years ago | James Kavanagh
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'myadvice' is defined
  3. 0

    Alfresco Maven Junit test

    Stack Overflow | 3 years ago | caldicot
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ServiceRegistry' is defined
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Using Groovy command line script to exectue Java Spring Beans how do I stop the NoSuchBeanDefinitionException?

    Stack Overflow | 4 years ago | fergjo
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'gapAnalyzer' is defined
  6. 0

    Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer - Spring Forum

    spring.io | 5 months ago
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'productService' is defined

  1. Andreas Häber 4 times, last 1 month ago
  2. Luka 2 times, last 2 months ago
  3. mortalman7 11 times, last 4 months ago
  4. serious2monkeys 5 times, last 3 months ago
  5. Kawada 1 times, last 7 months ago
3 more registered users
52 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.beans.factory.NoSuchBeanDefinitionException

    No bean named 'myadvice' is defined

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition()
  2. Spring Beans
    AbstractBeanFactory.getBean
    1. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
    2. org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
    3. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
    4. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    4 frames
  3. Spring Context
    AbstractApplicationContext.getBean
    1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    1 frame
  4. Spring AOP
    ProxyFactoryBean.getObject
    1. org.springframework.aop.framework.ProxyFactoryBean.initializeAdvisorChain(ProxyFactoryBean.java:454)
    2. org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:240)
    2 frames
  5. com.scansafe.prototype
    ThingammyCaptureAdvice.injectIntoContext
    1. com.scansafe.prototype.ThingammyCaptureAdvice.injectIntoContext(ThingammyCaptureAdvice.java:20)
    1 frame
  6. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:597)
    4 frames
  7. Spring AOP
    Cglib2AopProxy$DynamicAdvisedInterceptor.intercept
    1. org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    2. org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    3. org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
    4. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    5. org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    6. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    7. org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
    7 frames