org.springframework.beans.factory.BeanInitializationException

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.

  • 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.
    via by Abhijit Sarkar,
  • 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.
    via by 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' at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:95)[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:792)[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    No Bugmate found.