Skip to content

Commit a811f3e

Browse files
Mikhail Kuznetcovjoshiste
authored andcommitted
Add option to configure custom favicon
closes #903
1 parent d3a77f0 commit a811f3e

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

spring-boot-admin-docs/src/main/asciidoc/customizing.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ Either you just add the image to your jar-file in `/META-INF/spring-boot-admin-s
9595
or you must ensure yourself that the image gets served correctly (e.g. by registering your own `ResourceHandler`)
9696

9797
- **spring.boot.admin.ui.title**: Use this option to customize the browsers window title.
98+
99+
=== Customizing Page Favicon ===
100+
You can show custom browser favicon by using following configuration properties:
101+
102+
- **spring.boot.admin.ui.faviconBase**: Sets default icon, that is shown when all services are up.
103+
104+
- **spring.boot.admin.ui.faviconDanger**: Sets alerting icon that is shown when 1 or more services are down.
105+
106+
In first place you need get the icon of min 32x32 pixels in `.png` of `.ico` format - you can use one of online favicon generators for this).
107+
You should place the file into the assets folder of the ui subproject `/META-INF/spring-boot-admin-server-ui/assets/`.
108+
Then property should include path from root of the `/META-INF/spring-boot-admin-server-ui/` for example `assets/img/company-favicon.png`.
109+

spring-boot-admin-docs/src/main/asciidoc/server.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ In addition when the reverse proxy terminates the https connection, it may be ne
6363
| Page-Title to be shown.
6464
| `"Spring Boot Admin"`
6565

66+
| spring.boot.admin.ui.faviconBase
67+
| Custom favicon when all services are up
68+
| `"assets/img/favicon.png"`
69+
70+
| spring.boot.admin.ui.faviconDanger
71+
| Custom favicon when one or more services is down
72+
| `"assets/img/favicon-danger.png"`
73+
6674
|===
6775

6876
include::server-discovery.adoc[]

spring-boot-admin-server-ui/src/main/frontend/views/applications/handle.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
<script>
2929
export default {
30+
data: () => ({
31+
faviconBase: 'assets/img/favicon.png',
32+
faviconDanger: 'assets/img/favicon-danger.png',
33+
}),
3034
props: {
3135
applications: {
3236
type: Array,
@@ -44,6 +48,16 @@
4448
}, 0);
4549
}
4650
},
51+
created() {
52+
if (global.SBA && global.SBA.uiSettings) {
53+
if (global.SBA.uiSettings.favicon) {
54+
this.faviconBase = global.SBA.uiSettings.faviconBase
55+
}
56+
if (global.SBA.uiSettings.faviconDanger) {
57+
this.faviconDanger = global.SBA.uiSettings.faviconDanger
58+
}
59+
}
60+
},
4761
watch: {
4862
downCount(newVal, oldVal) {
4963
if ((newVal === 0) !== (oldVal === 0)) {
@@ -53,7 +67,7 @@
5367
},
5468
methods: {
5569
updateFavicon(up) {
56-
document.querySelector('link[rel*="icon"]').href = up ? 'assets/img/favicon.png' : 'assets/img/favicon-danger.png';
70+
document.querySelector('link[rel*="icon"]').href = up ? this.faviconBase : this.faviconDanger;
5771
}
5872
}
5973
};

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public UiController homeUiController() throws IOException {
6969
null ? this.uiProperties.getPublicUrl() : this.adminServerProperties.getContextPath(),
7070
this.uiProperties.getTitle(),
7171
this.uiProperties.getBrand(),
72+
this.uiProperties.getFaviconBase(),
73+
this.uiProperties.getFaviconDanger(),
7274
this.uiExtensions(),
7375
!this.applicationContext.getBeansOfType(NotificationFilterController.class).isEmpty()
7476
);

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public class AdminServerUiProperties {
4545
*/
4646
private String templateLocation = CLASSPATH_RESOURCE_LOCATIONS[0];
4747

48+
/**
49+
* Custom favicon. When all services are up
50+
*/
51+
private String faviconBase = null;
52+
53+
/**
54+
* Custom favicon. When one or more services is down
55+
*/
56+
private String faviconDanger = null;
57+
4858
/**
4959
* Page-Title to be shown.
5060
*/

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ public class UiController {
4444
public UiController(String publicUrl,
4545
String title,
4646
String brand,
47+
String faviconBase,
48+
String faviconDanger,
4749
List<UiExtension> uiExtensions,
4850
boolean notificationFilterEnabled) {
4951
this.publicUrl = publicUrl;
5052
this.uiSettings = new HashMap<>();
5153
this.uiSettings.put("title", title);
5254
this.uiSettings.put("brand", brand);
55+
this.uiSettings.put("faviconBase", faviconBase);
56+
this.uiSettings.put("faviconDanger", faviconDanger);
5357
this.uiSettings.put("notificationFilterEnabled", notificationFilterEnabled);
5458
this.cssExtensions = uiExtensions.stream()
5559
.filter(e -> e.getResourcePath().endsWith(".css"))

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void should_use_scheme_host_and_path_from_public_url() throws Exception {
7171
}
7272

7373
private MockMvc setupController(String publicUrl) {
74-
return MockMvcBuilders.standaloneSetup(new UiController(publicUrl, "", "", Collections.emptyList(), false))
74+
return MockMvcBuilders.standaloneSetup(new UiController(publicUrl, "", "", "", "", Collections.emptyList(), false))
7575
.setCustomHandlerMapping(() -> new AdminControllerHandlerMapping(""))
7676
.build();
7777
}

0 commit comments

Comments
 (0)