question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document configuration for spring boot application

See original GitHub issue

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:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sbordetcommented, Oct 30, 2018

@jaypatel512 SpringBootServletInitializer implements WebApplicationInitializer and I was not able to make it work either. Probably something changed in Spring Boot. However, it works if you implement ServletContextInitializer. Try to dig into the Spring Boot documentation.

0reactions
sbordetcommented, Oct 30, 2018

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 use ServerAnnotationProcessor to process CometD-specific annotations.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found