getting-started.adoc 6.33 KB
Newer Older
1 2 3 4
[[getting-started]]
== Getting started ==

[[set-up-admin-server]]
5
=== Setting up Spring Boot Admin Server ===
6

Johannes Edmeier committed
7
First you need to setup your server. To do this just setup a simple boot project (using http://start.spring.io). As Spring Boot Admin Server is capable of running as servlet or webflux application, you need to decide on this and add the according Spring Boot Starter. In this example we're using the servlet web starter.
8

9
. Add Spring Boot Admin Server starter to your dependencies:
10 11 12 13
+
[source,xml,subs="verbatim,attributes"]
.pom.xml
----
Johannes Edmeier committed
14 15 16 17 18 19 20 21 22
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>{project-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
23 24
----

25
. Pull in the Spring Boot Admin Server configuration via adding `@EnableAdminServer` to your configuration:
26 27 28 29 30 31 32 33 34 35 36 37 38
+
[source,java]
----
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}
----

39
NOTE: If you want to setup the Spring Boot Admin Server via war-deployment in a servlet-container, please have a look at the https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-samples/spring-boot-admin-sample-war/[spring-boot-admin-sample-war].
40

Johannes Edmeier committed
41
See also the https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-servlet/[spring-boot-admin-sample-servlet] project, which also adds security.
42 43

[[register-client-applications]]
44
=== Registering client applications ===
45

46
To register your application at the SBA Server you can either include the SBA Client or use http://projects.spring.io/spring-cloud/spring-cloud.html[Spring Cloud Discovery] (e.g. Eureka, Consul, ...). There is also a <<spring-cloud-discovery-static-config,simple option using a static configuration on the SBA Server side>>.
47 48

[[register-clients-via-spring-boot-admin]]
49
==== Spring Boot Admin Client ====
50

Johannes Edmeier committed
51
Each application that wants to register has to include the Spring Boot Admin Client. In order to secure the endpoints also add the `spring-boot-starter-security`.
52 53 54 55 56 57 58 59

. Add spring-boot-admin-starter-client to your dependencies:
+
[source,xml,subs="verbatim,attributes"]
.pom.xml
----
<dependency>
    <groupId>de.codecentric</groupId>
60
    <artifactId>spring-boot-admin-starter-client</artifactId>
61 62
    <version>{project-version}</version>
</dependency>
Johannes Edmeier committed
63 64 65 66
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
67 68
----

69
. Enable the SBA Client by configuring the URL of the Spring Boot Admin Server:
70 71 72 73
+
[source,yml]
.application.yml
----
Johannes Edmeier committed
74 75
spring.boot.admin.client.url: "http://localhost:8080"  #<1>
management.endpoints.web.exposure.include: "*"  #<2>
76
----
77
<1> The URL of the Spring Boot Admin Server to register at.
Johannes Edmeier committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
<2> As with Spring Boot 2 most of the endpoints aren't exposed via http by default, we expose all of them. For production you should carefully choose which endpoints to expose.

. Make the actuator endpoints accessible:
+
[source,java]
----
    @Configuration
    public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().permitAll()  //<1>
                .and().csrf().disable();
        }
    }
----
<1> For the sake of brevity we're disabling the security for now. Have a look at the <<securing-spring-boot-admin,security section>> on how to deal with secured endpoints.

95 96 97 98

[[discover-clients-via-spring-cloud-discovery]]
==== Spring Cloud Discovery ====

Johannes Edmeier committed
99
If you already use Spring Cloud Discovery for your applications you don't need the SBA Client. Just add a DiscoveryClient to Spring Boot Admin Server, the rest is done by our AutoConfiguration.
100

Johannes Edmeier committed
101
The following steps uses Eureka, but other Spring Cloud Discovery implementations are supported as well. There are examples using https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-consul/[Consul] and https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-zookeeper/[Zookeeper].
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

Also have a look at the http://projects.spring.io/spring-cloud/spring-cloud.html[Spring Cloud documentation].

. Add spring-cloud-starter-eureka to you dependencies:
+
[source,xml]
.pom.xml
----
include::{samples-dir}/spring-boot-admin-sample-eureka/pom.xml[tags=dependency-eureka,indent=0]
----

. Enable discovery by adding `@EnableDiscoveryClient` to your configuration:
+
[source,java]
----
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }

    @Configuration
    public static class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().anyRequest().permitAll()  //<1>
                .and().csrf().disable();
        }
    }
}
135
----
Johannes Edmeier committed
136 137
<1> For the sake of brevity we're disabling the security for now. Have a look at the <<securing-spring-boot-admin,security section>> on how to deal with secured endpoints.

138 139 140 141 142 143 144 145

. Tell the Eureka client where to find the service registry:
+
[source,yml]
.application.yml
----
include::{samples-dir}/spring-boot-admin-sample-eureka/src/main/resources/application.yml[tags=configuration-eureka]
----
146
<1> Configuration section for the Eureka client
Johannes Edmeier committed
147
<2> As with Spring Boot 2 most of the endpoints aren't exposed via http by default, we expose all of them. For production you should carefully choose which endpoints to expose.
148 149 150

See also https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-eureka/[spring-boot-admin-sample-eureka].

151
TIP: You can include the Spring Boot Admin Server to your Eureka server. Setup everything as described above and set `spring.boot.admin.context-path` to something different than `"/"` so that the Spring Boot Admin Server UI won't clash with Eureka's one.