Document configuration for spring boot application
See original GitHub issueIssue Description
Describe how to configure cometd with spring boot application.
@Configuration @EnableAutoConfiguration public class WebsocketConfiguration {
private static Logger logger = LoggerFactory.getLogger(WebsocketConfiguration.class);
@Bean
public JettyEmbeddedServletContainerFactory servletContainerFactory() {
JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
factory.addServerCustomizers(new JettyServerCustomizer(){
@Override
public void customize(Server server) {
try {
WebSocketServerContainerInitializer.configureContext((WebAppContext)server.getHandler());
} catch (ServletException e) {
logger.error(e.getMessage());
}
}
});
return factory;
}
@Bean
public ServletRegistrationBean servletRegistrationBean(){
CometDServlet cometdServlet = new CometDServlet();
return new ServletRegistrationBean(cometdServlet,"/cometd/*");
}
@Bean
public FilterRegistrationBean filterRegistration() {
FilterRegistrationBean filter = new FilterRegistrationBean();
CrossOriginFilter crossOriginFilter = new CrossOriginFilter();
filter.setFilter(crossOriginFilter);
filter.setAsyncSupported(true);
filter.setName("cross-origin");
filter.addUrlPatterns("/cometd/*","/chat/template/*");
return filter;
}
@Bean
public ServletContextInitializer initializer() {
return new ServletContextInitializer() {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer(servletContext));
}
};
}
@Bean
public BayeuxServer bayeuxServer(ServletContext servletContext)
{
BayeuxServerImpl bean = new BayeuxServerImpl();
bean.addExtension(new org.cometd.server.ext.AcknowledgedMessagesExtension());
bean.setOption(ServletContext.class.getName(), servletContext);
bean.setOption("ws.cometdURLMapping", "/cometd/*");
return bean;
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spring Boot Reference Documentation
Spring Boot helps you to create stand-alone, production-grade Spring-based applications that you can run. We take an opinionated view of the Spring platform...
Read more >Spring Boot Reference Documentation
Introducing Spring Boot, System Requirements, Servlet Containers, Installing Spring Boot, and Developing Your First Spring Boot Application.
Read more >Documentation Overview - Spring
This section provides a brief overview of Spring Boot reference documentation. It serves as a map for the rest of the document. The...
Read more >Spring Boot Reference Guide
The Spring Boot reference guide is available as html, pdf and epub documents. The latest copy is available at docs.spring.io/spring-boot/docs/current/reference.
Read more >Spring Boot Reference Documentation
Developing Your First Spring Boot Application. ... Disabling Specific Auto-configuration Classes . ... web-site for a wealth of reference documentation.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jaypatel512
SpringBootServletInitializer
implementsWebApplicationInitializer
and I was not able to make it work either. Probably something changed in Spring Boot. However, it works if you implementServletContextInitializer
. Try to dig into the Spring Boot documentation.It should be doable, as documented.
The idea is that instead of having
AnnotationCometDServlet
play the role of the dependency injection container, you let Spring do that, and only useServerAnnotationProcessor
to process CometD-specific annotations.