Avoid using reflection when configuring Tomcat listener

This benefits native image building and AOT compilation,
as reflection requires manual configuration.

See gh-22329
pull/22344/head
Filip Hanik 4 years ago committed by Andy Wilkinson
parent 177b3918ee
commit be7048b58f

@ -16,8 +16,9 @@
package org.springframework.boot.autoconfigure.websocket.reactive;
import org.apache.tomcat.websocket.server.WsContextListener;
import java.util.Collections;
import org.apache.tomcat.websocket.server.WsSci;
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;
@ -33,7 +34,8 @@ public class TomcatWebSocketReactiveWebServerCustomizer
@Override
public void customize(TomcatReactiveWebServerFactory factory) {
factory.addContextCustomizers((context) -> context.addApplicationListener(WsContextListener.class.getName()));
factory.addContextCustomizers((context) ->
context.addServletContainerInitializer(new WsSci(), Collections.emptySet()));
}
@Override

@ -16,8 +16,9 @@
package org.springframework.boot.autoconfigure.websocket.servlet;
import org.apache.tomcat.websocket.server.WsContextListener;
import java.util.Collections;
import org.apache.tomcat.websocket.server.WsSci;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;
@ -35,7 +36,8 @@ public class TomcatWebSocketServletWebServerCustomizer
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers((context) -> context.addApplicationListener(WsContextListener.class.getName()));
factory.addContextCustomizers((context) ->
context.addServletContainerInitializer(new WsSci(), Collections.emptySet()));
}
@Override

Loading…
Cancel
Save