Actuator in a non-boot application

At SpringOne 2GX 2013 Spring Boot was released which contains a module Spring Boot - Actuator which provides a series of endpoints to help manage your spring application. At a thousand foot level it reads properties and spring beans then returns a JSON view. It allows direct access to non functional application information without having to open an IDE or a command prompt. A few endpoints it provides out of the box:

/infoActuator adds /info endpoint by default. It contains commit, timestamp, information from the git.properties if it exists and any properties in the environment that has a prefix of info.
/health Indicates if the application is healthy or not by returning a an empty response with a status of 200. To customize the response simply add a bean of type HealthIndicator to your application context.
/beansWill return a response of all the spring beans in Spring Context.
/envLists environment properties which includes spring profiles, commandline arguments, servletContextInitParams, systemProperties and system environment.
/dumpDumps detailed information about all threads in the application.
/metricsResponse returns a response that is compatible with [Graphite](http://graphite.wikidot.com/) that contains metrics about the application. Attributes include how much memory is free and available, the number of processors, the average number of milliseconds each different type of request has taken since the start of the app, etc.
/traceReturns an array with detailed response information.
/autoconfigurationreportExposes all elements that have been auto configured
/shutdownAn endpoint that shuts down the ApplicationContext


Since the module is under the spring boot umbrella one might assume that actuator itself cannot be used w/ out boot. Since actuator is just a series of spring beans under the covers there is no reason why you can't integrate in a non-boot app. Here is a few steps on how to integrate actuator into your existing spring applications.

Add spring-boot-actuator as a maven dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-actuator</artifactId>
    <version>0.5.0.M6</version>
</dependency>

Create a configuration class

It will look a bit different depending on if you are using Java Config or standard xml configuration.

JavaConfig

@Configuration
@Import({
    EndpointAutoConfiguration.class
})
public class SpringBootActuatorConfig {

    @Bean
    public EndpointHandlerMapping endpointHandlerMapping() {
        return new EndpointHandlerMapping();
    }

    @Bean
    public EndpointHandlerAdapter endpointHandlerAdapter() {
        return new EndpointHandlerAdapter();
    }
}

XML config

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <bean name="endpointHandlerAdapter" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter" />
    <bean name="endpointHandlerMapping" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping" />
    <bean class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$InfoPropertiesConfiguration" />
    <bean name="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />

    <beans>
        <context:annotation-config />
        <bean name="endpointAutoConfiguration" class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration"/>
    </beans>
</beans>

Add application.properties - optional

If properties are defined, a node will appear in the /env url. So for instance, a properties file

info.url.java.examples=http://www.leveluplunch.com/java/examples/
info.url.java.exercises=http://www.leveluplunch.com/java/exercises/

will be outputted to /env

...
class path resource [com/levelup/properties/application.properties]: {
  url.java.examples: "http://www.leveluplunch.com/java/examples/",
  url.java.exercises: "http://www.leveluplunch.com/java/exercises/"
}
...

Next fire up your favorite server and access one of the urls above.