Closed
Description
Abhijit Sarkar opened SPR-13681 and commented
I've a request scoped bean:
@Component
@Scope(value = SCOPE_REQUEST, proxyMode = TARGET_CLASS)
public class RequestContextImpl implements RequestContext, Cloneable {
@EventListener
void setServiceId(ServiceIdFoundEvent event) {
this.serviceId = event.getServiceId();
}
}
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
}
that fails the context initialization with the following error message:
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]
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.
Affects: 4.2 GA
Issue Links:
- EventListenerMethodProcessor unconditionally instantiates certain beans, leading to BeanCreationException during deployment [SPR-13526] #18103 EventListenerMethodProcessor unconditionally instantiates certain beans, leading to BeanCreationException during deployment
- EventListenerMethodProcessor resolves classes of lazy beans causing NoClassDefFoundError [SPR-13712] #17619 EventListenerMethodProcessor resolves classes of lazy beans causing NoClassDefFoundError
Referenced from: commits 24e4f56