0
# Application Registration
1
2
Application registration provides programmatic control over how and when a Spring Boot application registers itself with Spring Boot Admin servers. While automatic registration is the default behavior, you can manually control the registration process for advanced use cases.
3
4
## Core Interfaces
5
6
### ApplicationRegistrator
7
8
```java { .api }
9
public interface ApplicationRegistrator {
10
/**
11
* Registers the client application at spring-boot-admin-server.
12
* @return true if successful registration on at least one admin server
13
*/
14
boolean register();
15
16
/**
17
* Tries to deregister currently registered application
18
*/
19
void deregister();
20
21
/**
22
* @return the id of this client as given by the admin server.
23
* Returns null if the client has not registered against the admin server yet.
24
*/
25
String getRegisteredId();
26
}
27
```
28
29
### Application Model
30
31
```java { .api }
32
public class Application {
33
// Create a new application builder
34
public static Builder create(String name);
35
36
// Application properties (all immutable)
37
public String getName();
38
public String getManagementUrl();
39
public String getHealthUrl();
40
public String getServiceUrl();
41
public Map<String, String> getMetadata();
42
43
public static class Builder {
44
public Builder name(String name);
45
public Builder managementUrl(String managementUrl);
46
public Builder healthUrl(String healthUrl);
47
public Builder serviceUrl(String serviceUrl);
48
public Builder metadata(String key, String value);
49
public Builder metadata(Map<String, String> metadata);
50
public Application build();
51
}
52
}
53
```
54
55
### ApplicationFactory
56
57
```java { .api }
58
public interface ApplicationFactory {
59
/**
60
* Create an Application instance from current configuration
61
*/
62
Application createApplication();
63
}
64
```
65
66
## Registration Implementations
67
68
### DefaultApplicationRegistrator
69
70
```java { .api }
71
public class DefaultApplicationRegistrator implements ApplicationRegistrator {
72
public DefaultApplicationRegistrator(
73
ApplicationFactory applicationFactory,
74
RegistrationClient registrationClient,
75
String[] adminUrl,
76
boolean registerOnce
77
);
78
}
79
```
80
81
### RegistrationApplicationListener
82
83
```java { .api }
84
public class RegistrationApplicationListener {
85
public void setAutoRegister(boolean autoRegister);
86
public void setAutoDeregister(boolean autoDeregister);
87
public void setRegisterPeriod(Duration registerPeriod);
88
}
89
```
90
91
## HTTP Client Support
92
93
### RegistrationClient Interface
94
95
```java { .api }
96
public interface RegistrationClient {
97
/**
98
* Register application with admin server
99
* @param adminUrl The admin server URL
100
* @param self The application to register
101
* @return Registration ID from server
102
*/
103
String register(String adminUrl, Application self);
104
105
/**
106
* Deregister application from admin server
107
* @param adminUrl The admin server URL
108
* @param id The registration ID
109
*/
110
void deregister(String adminUrl, String id);
111
}
112
```
113
114
### Servlet Stack Implementation
115
116
```java { .api }
117
public class BlockingRegistrationClient implements RegistrationClient {
118
public BlockingRegistrationClient(RestTemplate restTemplate);
119
}
120
```
121
122
### Reactive Stack Implementation
123
124
```java { .api }
125
public class ReactiveRegistrationClient implements RegistrationClient {
126
public ReactiveRegistrationClient(WebClient webClient, Duration timeout);
127
}
128
```
129
130
## Manual Registration Example
131
132
```java
133
@Component
134
public class CustomRegistrationService {
135
136
private final ApplicationRegistrator registrator;
137
138
public CustomRegistrationService(ApplicationRegistrator registrator) {
139
this.registrator = registrator;
140
}
141
142
public void registerWithAdminServer() {
143
boolean success = registrator.register();
144
if (success) {
145
String registrationId = registrator.getRegisteredId();
146
log.info("Successfully registered with ID: {}", registrationId);
147
} else {
148
log.warn("Failed to register with admin server");
149
}
150
}
151
152
public void unregisterFromAdminServer() {
153
registrator.deregister();
154
log.info("Deregistered from admin server");
155
}
156
}
157
```
158
159
## Custom Application Factory
160
161
```java
162
@Component
163
public class CustomApplicationFactory implements ApplicationFactory {
164
165
private final InstanceProperties instanceProperties;
166
167
public CustomApplicationFactory(InstanceProperties instanceProperties) {
168
this.instanceProperties = instanceProperties;
169
}
170
171
@Override
172
public Application createApplication() {
173
return Application.create(instanceProperties.getName())
174
.serviceUrl("https://my-service.example.com")
175
.managementUrl("https://my-service.example.com/actuator")
176
.healthUrl("https://my-service.example.com/actuator/health")
177
.metadata("custom-tag", "custom-value")
178
.metadata("build-time", Instant.now().toString())
179
.build();
180
}
181
}
182
```
183
184
## Conditional Registration
185
186
```java
187
@Component
188
@ConditionalOnProperty(value = "app.admin.registration.enabled", havingValue = "true")
189
public class ConditionalRegistrationService {
190
191
private final ApplicationRegistrator registrator;
192
private final Environment environment;
193
194
public ConditionalRegistrationService(
195
ApplicationRegistrator registrator,
196
Environment environment) {
197
this.registrator = registrator;
198
this.environment = environment;
199
}
200
201
@EventListener(ApplicationReadyEvent.class)
202
public void onApplicationReady() {
203
if (shouldRegister()) {
204
registrator.register();
205
}
206
}
207
208
@EventListener(ContextClosedEvent.class)
209
public void onApplicationClosed() {
210
registrator.deregister();
211
}
212
213
private boolean shouldRegister() {
214
String[] profiles = environment.getActiveProfiles();
215
return Arrays.asList(profiles).contains("production");
216
}
217
}
218
```
219
220
## Disabling Automatic Registration
221
222
To take full manual control, disable automatic registration:
223
224
```properties
225
# Disable automatic registration
226
spring.boot.admin.client.auto-registration=false
227
spring.boot.admin.client.auto-deregistration=false
228
```
229
230
Then implement your own registration logic as shown in the examples above.
231
232
## Registration Lifecycle
233
234
1. **Application Startup**: If auto-registration is enabled, the application automatically registers
235
2. **Periodic Updates**: Registration is renewed based on the configured period
236
3. **Health Monitoring**: The admin server monitors the registered health URL
237
4. **Application Shutdown**: If auto-deregistration is enabled, the application deregisters
238
239
## Error Handling
240
241
Registration failures are logged but do not prevent application startup. The client will continue to retry registration based on the configured period until successful or the application shuts down.