|
| 1 | +--- |
| 2 | +sidebar_position: 10 |
| 3 | +sidebar_custom_props: |
| 4 | + icon: 'server' |
| 5 | +--- |
| 6 | + |
| 7 | +# Server Setup |
| 8 | + |
| 9 | +Setting up a Spring Boot Admin Server is straightforward and requires only a few steps. The server acts as the central |
| 10 | +monitoring hub for all your Spring Boot applications. |
| 11 | + |
| 12 | +## Creating the Admin Server |
| 13 | + |
| 14 | +### Step 1: Create a Spring Boot Project |
| 15 | + |
| 16 | +Use [Spring Initializr](https://start.spring.io) to create a new Spring Boot project, or add the dependencies to an |
| 17 | +existing project. |
| 18 | + |
| 19 | +### Step 2: Add Maven Dependencies |
| 20 | + |
| 21 | +Add the Spring Boot Admin Server starter and a web starter to your `pom.xml`: |
| 22 | + |
| 23 | +```xml title="pom.xml" |
| 24 | + |
| 25 | +<dependencies> |
| 26 | + <dependency> |
| 27 | + <groupId>de.codecentric</groupId> |
| 28 | + <artifactId>spring-boot-admin-starter-server</artifactId> |
| 29 | + <version>@VERSION@</version> |
| 30 | + </dependency> |
| 31 | + <dependency> |
| 32 | + <groupId>org.springframework.boot</groupId> |
| 33 | + <artifactId>spring-boot-starter-webmvc</artifactId> |
| 34 | + </dependency> |
| 35 | +</dependencies> |
| 36 | +``` |
| 37 | + |
| 38 | +For Gradle: |
| 39 | + |
| 40 | +```groovy title="build.gradle" |
| 41 | +dependencies { |
| 42 | + implementation 'de.codecentric:spring-boot-admin-starter-server:@VERSION@' |
| 43 | + implementation 'org.springframework.boot:spring-boot-starter-webmvc' |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +:::tip |
| 48 | +You can choose either Servlet (WebMVC) or Reactive (WebFlux) as your web stack. For reactive applications, use |
| 49 | +`spring-boot-starter-webflux` instead. |
| 50 | +::: |
| 51 | + |
| 52 | +### Step 3: Enable Admin Server |
| 53 | + |
| 54 | +Annotate your main application class with `@EnableAdminServer`: |
| 55 | + |
| 56 | +```java title="SpringBootAdminApplication.java" |
| 57 | +import org.springframework.boot.SpringApplication; |
| 58 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 59 | + |
| 60 | +import de.codecentric.boot.admin.server.config.EnableAdminServer; |
| 61 | + |
| 62 | +@SpringBootApplication |
| 63 | +@EnableAdminServer |
| 64 | +public class SpringBootAdminApplication { |
| 65 | + public static void main(String[] args) { |
| 66 | + SpringApplication.run(SpringBootAdminApplication.class, args); |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +The `@EnableAdminServer` annotation enables Spring Boot Admin Server by loading all required configuration through |
| 72 | +Spring's auto-discovery feature. |
| 73 | + |
| 74 | +### Step 4: Configure Application Properties |
| 75 | + |
| 76 | +Create or update your `application.yml` or `application.properties`: |
| 77 | + |
| 78 | +```yaml title="application.yml" |
| 79 | +spring: |
| 80 | + application: |
| 81 | + name: spring-boot-admin-server |
| 82 | + |
| 83 | +server: |
| 84 | + port: 8080 |
| 85 | + |
| 86 | +management: |
| 87 | + endpoints: |
| 88 | + web: |
| 89 | + exposure: |
| 90 | + include: "*" |
| 91 | + endpoint: |
| 92 | + health: |
| 93 | + show-details: ALWAYS |
| 94 | +``` |
| 95 | +
|
| 96 | +### Step 5: Run the Server |
| 97 | +
|
| 98 | +Start your application and navigate to `http://localhost:8080` to access the Spring Boot Admin UI. |
| 99 | + |
| 100 | +## Server Configuration Options |
| 101 | + |
| 102 | +### Custom Context Path |
| 103 | + |
| 104 | +If you want to run the Admin Server under a different context path: |
| 105 | + |
| 106 | +```yaml title="application.yml" |
| 107 | +spring: |
| 108 | + boot: |
| 109 | + admin: |
| 110 | + context-path: /admin # UI will be available at http://localhost:8080/admin |
| 111 | +``` |
| 112 | + |
| 113 | +### Customizing the Server Port |
| 114 | + |
| 115 | +```yaml title="application.yml" |
| 116 | +server: |
| 117 | + port: 9090 # Run on a different port |
| 118 | +``` |
| 119 | + |
| 120 | +## Servlet vs. Reactive |
| 121 | + |
| 122 | +Spring Boot Admin Server can run on either a Servlet or Reactive stack: |
| 123 | + |
| 124 | +### Servlet (Default) |
| 125 | + |
| 126 | +```xml |
| 127 | +
|
| 128 | +<dependency> |
| 129 | + <groupId>org.springframework.boot</groupId> |
| 130 | + <artifactId>spring-boot-starter-webmvc</artifactId> |
| 131 | +</dependency> |
| 132 | +``` |
| 133 | + |
| 134 | +Best for traditional servlet-based applications and when you need features like Jolokia (JMX support). |
| 135 | + |
| 136 | +### Reactive (WebFlux) |
| 137 | + |
| 138 | +```xml |
| 139 | +
|
| 140 | +<dependency> |
| 141 | + <groupId>org.springframework.boot</groupId> |
| 142 | + <artifactId>spring-boot-starter-webflux</artifactId> |
| 143 | +</dependency> |
| 144 | +``` |
| 145 | + |
| 146 | +Best for fully reactive applications and high-concurrency scenarios. |
| 147 | + |
| 148 | +## Deployment Options |
| 149 | + |
| 150 | +### Standalone JAR |
| 151 | + |
| 152 | +Build and run as a standalone application: |
| 153 | + |
| 154 | +```bash |
| 155 | +mvn clean package |
| 156 | +java -jar target/spring-boot-admin-server.jar |
| 157 | +``` |
| 158 | + |
| 159 | +### WAR Deployment |
| 160 | + |
| 161 | +For deployment to an external servlet container, see |
| 162 | +the [spring-boot-admin-sample-war](https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-war/) |
| 163 | +example. |
| 164 | + |
| 165 | +### Docker |
| 166 | + |
| 167 | +Create a `Dockerfile`: |
| 168 | + |
| 169 | +```dockerfile |
| 170 | +FROM eclipse-temurin:17-jre |
| 171 | +COPY target/spring-boot-admin-server.jar app.jar |
| 172 | +EXPOSE 8080 |
| 173 | +ENTRYPOINT ["java", "-jar", "/app.jar"] |
| 174 | +``` |
| 175 | + |
| 176 | +Build and run: |
| 177 | + |
| 178 | +```bash |
| 179 | +docker build -t spring-boot-admin-server . |
| 180 | +docker run -p 8080:8080 spring-boot-admin-server |
| 181 | +``` |
| 182 | + |
| 183 | +## Next Steps |
| 184 | + |
| 185 | +Now that your server is running, you need to register your applications: |
| 186 | + |
| 187 | +- [Client Registration](./20-client-registration.md) - Learn how to register applications with the server |
| 188 | +- [Server Configuration](../02-server/01-server.mdx) - Explore advanced server configuration options |
| 189 | +- [Security](../02-server/02-security.md) - Secure your Admin Server |
| 190 | + |
| 191 | +## Example Projects |
| 192 | + |
| 193 | +- [spring-boot-admin-sample-servlet](https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-servlet/) - |
| 194 | + Complete servlet-based example with security |
| 195 | +- [spring-boot-admin-sample-reactive](https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-reactive/) - |
| 196 | + Reactive (WebFlux) example |
0 commit comments