简体   繁体   中英

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?

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 ;)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM