Carlos Alberto
Carlos Alberto

Reputation: 8585

Spring Boot Actuator for custom Servlet

I noticed Spring Boot Actuator only works if your application uses Spring MVC (DispatcherServlet) to handle endpoints. By default, this servlet is included if you add the module spring-boot-starter-web into your project.

Once this servlet exists, the class EndpointWebMvcAutoConfiguration customize the Spring MVC to support endpoints and other management properties.

For record, my application implements a Vaadin Servlet to navigate on screens, so is there any way to enable Spring Boot Actuator in this case?

Upvotes: 0

Views: 2625

Answers (2)

Alejandro Duarte
Alejandro Duarte

Reputation: 1479

You can have both. If you have a VaadinServlet, you can try with something like:

@SpringBootApplication
public class AdminApplication {

    @Bean
    public ServletRegistrationBean<SpringVaadinServlet> springVaadinServlet() {
        SpringVaadinServlet servlet = new SpringVaadinServlet();
        ServletRegistrationBean<SpringVaadinServlet> registrationBean = new ServletRegistrationBean<>(servlet, "/your-web-app/*");
        registrationBean.setLoadOnStartup(1);
        registrationBean.setName("VaadinServlet");
        return registrationBean;
    }
}

@SpringUI(path = "/")
public class VaadinUI extends UI {
    ...
}

Notice the need for a registration name, a custom servlet mapping URL, and custom path in the @SpringUI annotation.

You can find a running demo here.

Upvotes: 0

Daniel Lavoie
Daniel Lavoie

Reputation: 1902

You won't be able to reuse the EndpointWebMVCAutoConfiguration class as it is explicitly conditionnal on DispatcherServlet.class. If you look at the implementation, you'll see that the Actuator has a lot of dependencies on Spring MVC.

It would be a little ballzy but you could consider implementing your own autoconfiguration class inspired by EndpointWebMVCAutoConfiguration.

I wish you good luck if you go down that path ;)

Upvotes: 1

Related Questions