Top Description Fields Constructors Methods
org.springframework.web.socket.server.standard

public Class ServerEndpointExporter

extends WebApplicationObjectSupport
implements InitializingBean, SmartInitializingSingleton
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.InitializingBean
Imports
java.util.Arrays, .LinkedHashSet, .List, .Map, .Set, jakarta.servlet.ServletContext, jakarta.websocket.DeploymentException, jakarta.websocket.server.ServerContainer, .ServerEndpoint, .ServerEndpointConfig, org.springframework.beans.factory.InitializingBean, .SmartInitializingSingleton, org.springframework.context.ApplicationContext, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.context.support.WebApplicationObjectSupport

Detects beans of type jakarta.websocket.server.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.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
4.0
See Also
ServerEndpointRegistration, SpringConfigurator, ServletServerContainerFactoryBean

Field Summary

Modifier and TypeField and Description
private List<Class<?>>
private ServerContainer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public void
afterSingletonsInstantiated()

Implements org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.

protected ServerContainer
getServerContainer()

Return the JSR-356 ServerContainer to use for endpoint registration.

protected void
initServletContext(ServletContext
the ServletContext that this application object runs in (never null)
servletContext
)

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty.

protected boolean
isContextRequired()

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.isContextRequired.

Overrides the base class behavior to enforce running in an ApplicationContext.

private void
registerEndpoint(Class<?> endpointClass)

private void
protected void
registerEndpoints()

Actually register the endpoints.

public void
setAnnotatedEndpointClasses(Class<?>...
ServerEndpoint-annotated types
annotatedEndpointClasses
)

Explicitly list annotated endpoint types that should be registered on startup.

public void
setServerContainer(ServerContainer serverContainer)

Set the JSR-356 ServerContainer to use for endpoint registration.

Inherited from org.springframework.web.context.support.WebApplicationObjectSupport:
getServletContextgetTempDirgetWebApplicationContextinitApplicationContextsetServletContext

Field Detail

annotatedEndpointClassesback to summary
private List<Class<?>> annotatedEndpointClasses
Annotations
@Nullable
serverContainerback to summary
private ServerContainer serverContainer
Annotations
@Nullable

Constructor Detail

ServerEndpointExporterback to summary
public ServerEndpointExporter()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
afterSingletonsInstantiatedback to summary
public void afterSingletonsInstantiated()

Implements org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Doc from org.springframework.beans.factory.SmartInitializingSingleton.afterSingletonsInstantiated.

Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already. ListableBeanFactory#getBeansOfType calls within this method won't trigger accidental side effects during bootstrap.

Note

This callback won't be triggered for singleton beans lazily initialized on demand after BeanFactory bootstrap, and not for any other bean scope either. Carefully use it for beans with the intended bootstrap semantics only.

Annotations
@Override
getServerContainerback to summary
protected ServerContainer getServerContainer()

Return the JSR-356 ServerContainer to use for endpoint registration.

Annotations
@Nullable
initServletContextback to summary
protected void initServletContext(ServletContext servletContext)

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Doc from org.springframework.web.context.support.WebApplicationObjectSupport.initServletContext.

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty. Called by initApplicationContext(org.springframework.context.ApplicationContext) as well as setServletContext(jakarta.servlet.ServletContext).

Parameters
servletContext:ServletContext

the ServletContext that this application object runs in (never null)

Annotations
@Override
isContextRequiredback to summary
protected boolean isContextRequired()

Overrides org.springframework.web.context.support.WebApplicationObjectSupport.isContextRequired.

Doc from org.springframework.web.context.support.WebApplicationObjectSupport.isContextRequired.

Overrides the base class behavior to enforce running in an ApplicationContext. All accessors will throw IllegalStateException if not running in a context.

Annotations
@Override
registerEndpointback to summary
private void registerEndpoint(Class<?> endpointClass)
registerEndpointback to summary
private void registerEndpoint(ServerEndpointConfig endpointConfig)
registerEndpointsback to summary
protected void registerEndpoints()

Actually register the endpoints. Called by afterSingletonsInstantiated().

setAnnotatedEndpointClassesback to summary
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:Class<?>[]

ServerEndpoint-annotated types

setServerContainerback to summary
public void setServerContainer(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.