Class ServerEndpointExporter
- All Implemented Interfaces:
Aware
,InitializingBean
,SmartInitializingSingleton
,ApplicationContextAware
,ServletContextAware
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
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
Return the JSR-356ServerContainer
to use for endpoint registration.protected void
initServletContext
(ServletContext servletContext) Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.protected boolean
Overrides the base class behavior to enforce running in an ApplicationContext.protected void
Actually register the endpoints.void
setAnnotatedEndpointClasses
(Class<?>... annotatedEndpointClasses) Explicitly list annotated endpoint types that should be registered on startup.void
setServerContainer
(ServerContainer serverContainer) Set the JSR-356ServerContainer
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
-
Constructor Details
-
ServerEndpointExporter
public ServerEndpointExporter()
-
-
Method Details
-
setAnnotatedEndpointClasses
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
Set the JSR-356ServerContainer
to use for endpoint registration. If not set, the container is going to be retrieved via theServletContext
. -
getServerContainer
Return the JSR-356ServerContainer
to use for endpoint registration. -
initServletContext
Description copied from class:WebApplicationObjectSupport
Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.The default implementation is empty. Called by
WebApplicationObjectSupport.initApplicationContext(org.springframework.context.ApplicationContext)
as well asWebApplicationObjectSupport.setServletContext(jakarta.servlet.ServletContext)
.- Overrides:
initServletContext
in classWebApplicationObjectSupport
- Parameters:
servletContext
- the ServletContext that this application object runs in (nevernull
)
-
isContextRequired
protected boolean isContextRequired()Description copied from class:WebApplicationObjectSupport
Overrides the base class behavior to enforce running in an ApplicationContext. All accessors will throw IllegalStateException if not running in a context.- Overrides:
isContextRequired
in classWebApplicationObjectSupport
- See Also:
-
afterPropertiesSet
public void afterPropertiesSet()Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()Description copied from interface:SmartInitializingSingleton
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(java.lang.Class<T>)
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.- Specified by:
afterSingletonsInstantiated
in interfaceSmartInitializingSingleton
-
registerEndpoints
protected void registerEndpoints()Actually register the endpoints. Called byafterSingletonsInstantiated()
.
-