Skip to content

Commit bd11afa

Browse files
author
Johannes Stelzer
committed
Support automatic discovery via Spring Clouds DiscoveryClient.
To enable, you just have to add a DiscoveryClient to your Spring Boot Admin Server. Also did some code polish. Closes #44
1 parent 912d4f7 commit bd11afa

File tree

24 files changed

+564
-34
lines changed

24 files changed

+564
-34
lines changed

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@
222222
<version>${spring-boot.version}</version>
223223
</dependency>
224224

225+
<dependency>
226+
<groupId>org.springframework.cloud</groupId>
227+
<artifactId>spring-cloud-starter</artifactId>
228+
<version>${spring-cloud.version}</version>
229+
</dependency>
225230
<dependency>
226231
<groupId>org.springframework.cloud</groupId>
227232
<artifactId>spring-cloud-starter-zuul</artifactId>
@@ -237,6 +242,11 @@
237242
<artifactId>spring-cloud-commons</artifactId>
238243
<version>${spring-cloud.version}</version>
239244
</dependency>
245+
<dependency>
246+
<groupId>org.springframework.cloud</groupId>
247+
<artifactId>spring-cloud-starter-eureka</artifactId>
248+
<version>${spring-cloud.version}</version>
249+
</dependency>
240250

241251
<dependency>
242252
<groupId>org.apache.commons</groupId>
@@ -262,6 +272,7 @@
262272
</dependency>
263273
</dependencies>
264274
</dependencyManagement>
275+
265276
<repositories>
266277
<repository>
267278
<id>spring-release</id>

spring-boot-admin-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</properties>
2121
<modules>
2222
<module>spring-boot-admin-sample</module>
23+
<module>spring-boot-admin-sample-discovery</module>
2324
<module>spring-boot-admin-sample-hazelcast</module>
2425
</modules>
2526
</project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target
2+
/.settings
3+
/.classpath
4+
/.project
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>de.codecentric</groupId>
6+
<artifactId>spring-boot-admin-samples</artifactId>
7+
<version>1.1.3-SNAPSHOT</version>
8+
<relativePath>..</relativePath>
9+
</parent>
10+
<artifactId>spring-boot-admin-sample-discovery</artifactId>
11+
<dependencies>
12+
<dependency>
13+
<groupId>de.codecentric</groupId>
14+
<artifactId>spring-boot-admin-server</artifactId>
15+
</dependency>
16+
<dependency>
17+
<groupId>de.codecentric</groupId>
18+
<artifactId>spring-boot-admin-server-ui</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.springframework.cloud</groupId>
22+
<artifactId>spring-cloud-starter-eureka</artifactId>
23+
</dependency>
24+
</dependencies>
25+
<build>
26+
<finalName>${project.artifactId}</finalName>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-compiler-plugin</artifactId>
31+
</plugin>
32+
<plugin>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-maven-plugin</artifactId>
35+
<executions>
36+
<execution>
37+
<goals>
38+
<goal>repackage</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
<configuration>
43+
<mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass>
44+
<addResources>false</addResources>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.codecentric.boot.admin;
17+
18+
import org.springframework.boot.SpringApplication;
19+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
20+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
import de.codecentric.boot.admin.config.EnableAdminServer;
24+
25+
@Configuration
26+
@EnableAutoConfiguration
27+
@EnableDiscoveryClient
28+
@EnableAdminServer
29+
public class SpringBootAdminApplication {
30+
31+
public static void main(String[] args) {
32+
SpringApplication.run(SpringBootAdminApplication.class, args);
33+
}
34+
35+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
info:
2+
version: 1.0.0
3+
4+
spring:
5+
application:
6+
name: discovery-example
7+
cloud:
8+
config:
9+
enabled: false
10+
11+
eureka:
12+
instance:
13+
leaseRenewalIntervalInSeconds: 5
14+
metadataMap:
15+
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
16+
client:
17+
serviceUrl:
18+
defaultZone: http://localhost:8761/eureka/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml"/>
4+
<jmxConfigurator/>
5+
</configuration>

spring-boot-admin-samples/spring-boot-admin-sample/src/main/resources/application.properties

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
info:
2+
version: @pom.version@
3+
stage: test
4+
5+
6+
7+
spring:
8+
application:
9+
name: @pom.artifactId@
10+
boot:
11+
admin:
12+
url=http://localhost:8080
13+
cloud:
14+
config:
15+
enabled: false
16+
17+
endpoints:
18+
health:
19+
sensitive: false

spring-boot-admin-server/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ public class Application {
3030
}
3131
```
3232

33-
## Hazelcast Support
33+
## Spring Cloud DiscoveryClient support
34+
The Spring Boot Admin Server is capable of using Spring Clouds DiscoveryClient to discover applications. When you do this the clients don't have to include the spring-boot-starter-admin-client. You just have to configure a DiscoveryClient - everything else is done by AutoConfiguration.
35+
See the [discovery sample project](https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-discovery) in this repository.
36+
37+
One note: If you omit the Spring Boot Admin Client in you Client Applications you can't download the logfile (but hopefully my pull request will make it into Spring Boot 1.3.0);
38+
39+
### Further configuration
40+
Since the DiscoveryClient doesn't tell the management.context-path you can suffix the url for all discovered clients by setting ``spring.boot.admin.discovery.management.context-path``.
41+
42+
Explictly disable DiscoveryClient support by setting ``spring.boot.admin.discover.enable=false``.
3443

44+
## Hazelcast Support
3545
Spring Boot Admin Server supports cluster replication with Hazelcast.
3646
It is automatically enabled when its found on the classpath.
3747

@@ -47,7 +57,7 @@ Just add Hazelcast to your dependencies:
4757
And thats it! The server is going to use the default Hazelcast configuration.
4858

4959
### Custom Hazelcast configuration
50-
To change the configuration add a com.hazelcast.config.Config bean to your application context (for example with hazelcast-spring):
60+
To change the configuration add a ``com.hazelcast.config.Config``-bean to your application context (for example with hazelcast-spring):
5161

5262
Add hazelcast-spring to dependencies:
5363
```xml
@@ -83,6 +93,6 @@ Write xml-config hazelcast-config.xml:
8393
```
8494

8595
### Further configuration
86-
To disable Hazelcast support by setting ``spring.boot.admin.hazelcast.enable=false``.
96+
Disable Hazelcast support by setting ``spring.boot.admin.hazelcast.enable=false``.
8797

8898
To alter the name of the Hazelcast-Map set ``spring.boot.admin.hazelcast.map= my-own-map-name``.

0 commit comments

Comments
 (0)