Class ServerEndpointExporter

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.socket.server.standard.ServerEndpointExporter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware

public class ServerEndpointExporter extends org.springframework.web.context.support.WebApplicationObjectSupport implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton
Detects beans of type ServerEndpointConfig and registers with the standard Jakarta WebSocket runtime. Also detects beans annotated with ServerEndpoint and registers them as well. Although not required, it is likely annotated endpoints should have their configurator property set to SpringConfigurator.

When this class is used, by declaring it in Spring configuration, it should be possible to turn off a Servlet container's scan for WebSocket endpoints. This can be done with the help of the <absolute-ordering> element in web.xml.

Since:
4.0
Author:
Rossen Stoyanchev, Juergen Hoeller
See Also:
  • Field Summary

    Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
     
    protected @Nullable jakarta.websocket.server.ServerContainer
    Return the JSR-356 ServerContainer to use for endpoint registration.
    protected void
    initServletContext(jakarta.servlet.ServletContext servletContext)
     
    protected boolean
     
    protected void
    Actually register the endpoints.
    void
    setAnnotatedEndpointClasses(Class<?>... annotatedEndpointClasses)
    Explicitly list annotated endpoint types that should be registered on startup.
    void
    setServerContainer(@Nullable jakarta.websocket.server.ServerContainer serverContainer)
    Set the JSR-356 ServerContainer to use for endpoint registration.

    Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport

    getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, setServletContext

    Methods inherited from class org.springframework.context.support.ApplicationObjectSupport

    getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ServerEndpointExporter

      public ServerEndpointExporter()
  • Method Details

    • setAnnotatedEndpointClasses

      public void setAnnotatedEndpointClasses(Class<?>... annotatedEndpointClasses)
      Explicitly list annotated endpoint types that should be registered on startup. This can be done if you wish to turn off a Servlet container's scan for endpoints, which goes through all 3rd party jars in the classpath, and rely on Spring configuration instead.
      Parameters:
      annotatedEndpointClasses - ServerEndpoint-annotated types
    • setServerContainer

      public void setServerContainer(@Nullable jakarta.websocket.server.ServerContainer serverContainer)
      Set the JSR-356 ServerContainer to use for endpoint registration. If not set, the container is going to be retrieved via the ServletContext.
    • getServerContainer

      protected @Nullable jakarta.websocket.server.ServerContainer getServerContainer()
      Return the JSR-356 ServerContainer to use for endpoint registration.
    • initServletContext

      protected void initServletContext(jakarta.servlet.ServletContext servletContext)
      Overrides:
      initServletContext in class org.springframework.web.context.support.WebApplicationObjectSupport
    • isContextRequired

      protected boolean isContextRequired()
      Overrides:
      isContextRequired in class org.springframework.web.context.support.WebApplicationObjectSupport
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Specified by:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton
    • registerEndpoints

      protected void registerEndpoints()
      Actually register the endpoints. Called by afterSingletonsInstantiated().