Spring Boot Actuator without Spring Boot

First let’s clarify that you cannot use Spring Boot Actuator without using Spring Boot.

I was wrong about not being able to it without Spring Boot. See @stefaan-neyts
answer for an example of how to do it.

I created a sample project to show how you could convert a basic SpringMVC application using a minimal amount of Spring Boot auto-configuration.

Original source: http://www.mkyong.com/spring-mvc/gradle-spring-mvc-web-project-example

Converted source: https://github.com/Pytry/minimal-boot-actuator

I could have completely removed the dispatcher-servlet.xml and the web.xml files, but I kept them to show how to perform as minimal a change as possible and to simplify converting more complex projects.

Here is a list of steps I took to convert.

Conversion Process

  • Add a Java Configuration file annotated with @SpringBootApplication
  • Add the Application configuration file as a bean to the traditional xml configuration ( added it just after the context scan).
  • Move view resolvers into Application java configuration.

    Alternatively, add the prefix and suffix to application.properties.
    You can then inject them with @Value in your application, or delete it entirely and just use the provided spring boot view resolver.
    I went with the former.

  • Removed Default context listener from the spring context xml.

    This is important!
    Since spring boot will provide one you will get an “Error listener Start” exception if you do not.

  • Add the spring boot plugin to your build script dependencies (I was using gradle)

  • Add a mainClassName property to the build file, and set to an empty String (indicates not to create an executable).

  • Modify dependencies for spring boot actuator

Leave a Comment