0

I am having Spring-Boot w Vaadin project where I had to define some Spring-MVC REST controllers. While using Vaadin UI all is working fine. But when I invoke any of the REST controllers functionality wise all seems working but I can see in logs there is an exception thrown.

1102038 2017-08-09 09:36:12.223 [ajp-nio-8009-exec-5] DEBUG o.s.c.e.SimpleApplicationEventMulticaster - Non-matching event type for listener: org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer$$Lambda$102/980450043@270a6b1b 
java.lang.ClassCastException: org.springframework.web.context.support.ServletRequestHandledEvent cannot be cast to org.springframework.boot.web.context.WebServerInitializedEvent
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:353)
    at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1078)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009)
    at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:892)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:651)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:97)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilterAbstractAuthenticationProcessingFilter.java:200)

Thanks to the source code availability I started debugging and found that if I override org.springframework.context.event.GenericApplicationListenerAdapter.supportsEventType(ResolvableType eventType) like bellow everything is going back to normal.

    @Override
@SuppressWarnings("unchecked")
public boolean supportsEventType(ResolvableType eventType) {
    if (this.delegate instanceof SmartApplicationListener) {
        Class<? extends ApplicationEvent> eventClass = (Class<? extends ApplicationEvent>) eventType.resolve();
        return (eventClass != null &&
                ((SmartApplicationListener) this.delegate).supportsEventType(eventClass));
    } else
        return (this.declaredEventType == null ||
                (this.declaredEventType.isAssignableFrom(eventType) &&
                 !this.declaredEventType.getType().toString().equals("E")));
}

(I have added !this.declaredEventType.getType().toString().equals("E") to the last return statement)

Question: Should I stick with this hack or just might miss something in a configuration? Thanks in advance.

1 Answers1

2

You haven't missed anything in your configuration. The ClassCastException is due to a bug in Spring Framework 5.0 RC3. It's been fixed in the latest snapshots. You could stick with your hack for now, or you could switch to using Spring Framework snapshots (that are available from https://repo.spring.io/snapshot) by overriding spring.version in your pom.xml or build.gradle.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Thank you very much, Andy. I do appreciate that. I will prolly wait till RC4 comes out. Meanwhile, it's really strange I didn't find that Jira bug report. – Valery Tamashevich Aug 10 '17 at 14:06