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
  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'
  3. 0

    How to dynamically load Java classes at Runtime in OSGI framework?

    Stack Overflow | 5 years ago | Mridul Chopra
    org.springframework.beans.factory.BeanInitializationException: Could not find default strategy class for interface [org.springframework.ws.transport.WebServiceMessageSender]; nested exception is java.lang.ClassNotFoundException:org.springframework.ws.transport.http.HttpUrlConnectionMessageSender at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:126)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    incompatibilité becpg project avec un autre module - beCPG PLM Community - Forge beCPG

    becpg.fr | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'integrityChecker' defined in URL [jar:file:/opt/alfresco-4.2.f/tomcat/webapps/alfresco/WEB-INF/lib/alvex-documents-registers-ce-repo-1.33.jar!/alfresco/extension/alvex-documents-registers-context.xml]: Cannot resolve reference to bean 'alvex-master-data-service' while setting bean property 'alvexMasterDataService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AlvexMasterDataService' defined in URL [jar:file:/opt/alfresco-4.2.f/tomcat/webapps/alfresco/WEB-INF/lib/alvex-documents-registers-ce-repo-1.33.jar!/alfresco/extension/alvex-documents-registers-context.xml]: Cannot resolve reference to bean 'alvexMasterDataService' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alvexMasterDataService' defined in URL [jar:file:/opt/alfresco-4.2.f/tomcat/webapps/alfresco/WEB-INF/lib/alvex-documents-registers-ce-repo-1.33.jar!/alfresco/extension/alvex-documents-registers-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'documentsRegistersExtension' is required for bean 'alvexMasterDataService'
  6. 0

    When creating a context and then calling {{getBean}} on it from multiple threads we sometimes get a {{BeanInitializationException}} from {{RequiredAnnotationBeanPostProcessor.postProcessPropertyValues}}. Attached is a simple maven project to reproduce. In a loop it: 1. creates a fresh spring context 2. attempts to fetch some beans from it in parallel. The number of threads and max number of loop iterations can be passed as the first and second argument to the Main class. Usage: {{mvn clean package && java -jar target/spring-bug-1.0-SNAPSHOT-jar-with-dependencies.jar}} We never get any errors when the getBean method is called from a single thread, so: {{java -jar target/spring-bug-1.0-SNAPSHOT-jar-with-dependencies.jar 1}} always works. We don't get any errors for spring version 4.1.9, but as long as we switch to 4.2.0 or later the errors start occuring. Example exception: {code} Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service-2' defined in class path resource [example-context.xml]: Cannot resolve reference to bean 'bean_0_1' while setting bean property 'bean_0_1'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean_0_1' defined in URL [jar:file:/home/mpiela/devel/repo/spring-bug/target/spring-bug-1.0-SNAPSHOT-jar-with-dependencies.jar!/test/Bean_0_1.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Properties 'bean_1_0' and 'bean_1_1' are required for bean 'bean_0_1' at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054) at test.Main.lambda$tryToGetBean$0(Main.java:75) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean_0_1' defined in URL [jar:file:/home/mpiela/devel/repo/spring-bug/target/spring-bug-1.0-SNAPSHOT-jar-with-dependencies.jar!/test/Bean_0_1.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Properties 'bean_1_0' and 'bean_1_1' are required for bean 'bean_0_1' at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 13 more Caused by: org.springframework.beans.factory.BeanInitializationException: Properties 'bean_1_0' and 'bean_1_1' are required for bean 'bean_0_1' at org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.postProcessPropertyValues(RequiredAnnotationBeanPostProcessor.java:156) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ... 17 more {code}

    Spring JIRA | 7 months ago | Marcin Piela
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service-2' defined in class path resource [example-context.xml]: Cannot resolve reference to bean 'bean_0_1' while setting bean property 'bean_0_1'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean_0_1' defined in URL [jar:file:/home/mpiela/devel/repo/spring-bug/target/spring-bug-1.0-SNAPSHOT-jar-with-dependencies.jar!/test/Bean_0_1.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Properties 'bean_1_0' and 'bean_1_1' are required for bean 'bean_0_1'

  1. stigkj 5 times, last 3 weeks ago
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.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