org.springframework.beans.factory.BeanInitializationException: Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'

Spring JIRA | Abhijit Sarkar | 1 year ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    I've a request scoped bean: {code} @Component @Scope(value = SCOPE_REQUEST, proxyMode = TARGET_CLASS) public class RequestContextImpl implements RequestContext, Cloneable { @EventListener void setServiceId(ServiceIdFoundEvent event) { this.serviceId = event.getServiceId(); } } {code} {code} public class ServiceIdFoundEvent extends ApplicationEvent { private static final long serialVersionUID = -4841984309730357349L; public ServiceIdFoundEvent(Integer serviceId) { super(serviceId); } public int getServiceId() { return (Integer) source; } // equals and hashCode } {code} that fails the context initialization with the following error message: {code} INFO] [talledLocalContainer] 14:56:54.809 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed [INFO] [talledLocalContainer] org.springframework.beans.factory.BeanInitializationException: Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true' [INFO] [talledLocalContainer] at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:95) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] [INFO] [talledLocalContainer] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] [INFO] [talledLocalContainer] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] {code} Not only the message is wrong (it asks for CGLIB proxy which is {{ScopedProxyMode.TARGET_CLASS}}, it appears from the logs that the {{EventListenerMethodProcessor}} is trying to process the bean definition as a singleton.

    Spring JIRA | 1 year ago | Abhijit Sarkar
    org.springframework.beans.factory.BeanInitializationException: Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'
  2. 0

    I've a request scoped bean: {code} @Component @Scope(value = SCOPE_REQUEST, proxyMode = TARGET_CLASS) public class RequestContextImpl implements RequestContext, Cloneable { @EventListener void setServiceId(ServiceIdFoundEvent event) { this.serviceId = event.getServiceId(); } } {code} {code} public class ServiceIdFoundEvent extends ApplicationEvent { private static final long serialVersionUID = -4841984309730357349L; public ServiceIdFoundEvent(Integer serviceId) { super(serviceId); } public int getServiceId() { return (Integer) source; } // equals and hashCode } {code} that fails the context initialization with the following error message: {code} INFO] [talledLocalContainer] 14:56:54.809 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed [INFO] [talledLocalContainer] org.springframework.beans.factory.BeanInitializationException: Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true' [INFO] [talledLocalContainer] at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:95) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] [INFO] [talledLocalContainer] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] [INFO] [talledLocalContainer] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] {code} Not only the message is wrong (it asks for CGLIB proxy which is {{ScopedProxyMode.TARGET_CLASS}}, it appears from the logs that the {{EventListenerMethodProcessor}} is trying to process the bean definition as a singleton.

    Spring JIRA | 1 year ago | Abhijit Sarkar
    org.springframework.beans.factory.BeanInitializationException: Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'

  1. stigkj 5 times, last 5 months ago

Root Cause Analysis

  1. org.springframework.beans.factory.BeanInitializationException

    Failed to process @EventListener annotation on bean with name 'requestContextImpl'; nested exception is java.lang.IllegalStateException: @EventListener method 'setServiceId' found on bean target class 'RequestContextImpl', but not found in any interface(s) for bean JDK proxy. Either pull the method up to an interface or switch to subclass (CGLIB) proxies by setting proxy-target-class/proxyTargetClass attribute to 'true'

    at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated()
  2. Spring Context
    EventListenerMethodProcessor.afterSingletonsInstantiated
    1. org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:95)[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    1 frame
  3. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792)[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    1 frame
  4. Spring Context
    AbstractApplicationContext.finishBeanFactoryInitialization
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    1 frame