Search code examples
spring-bootcustomizationwarspring-boot-admin

(WAR) Spring Boot Admin custom view not found


Once deployed as a WAR into Tomcat, my customized SBA dashboard fails at showing a custom view that was first doing fine into a JAR (but it also fails now, btw)

This is where is located the extension's directory into the WAR: /WEB-INF/classes/META-INF/spring-boot-admin-server-ui/extensions/customz/...

REM: I've also customized the login page and my picture is located at /WEB-INF/classes/META-INF/spring-boot-admin-server-ui/assets/img/ so I guess that the classpath isn't the issue.

Still, I've got an error into the web browser's console, though: GET http://xx.xx.xx.xx:8080/extensions/customz/css/custom.fb3a4f29.css net::ERR_ABORTED 404

REM: according to my context path, the correct path should probably be that one: http://xx.xx.xx.xx:8080/myapp/dashboard/extensions/customz/css/custom.fb3a4f29.css

server.servlet.context-path=/myapp
spring.boot.admin.context-path=/dashboard

...

<packaging>war</packaging>
<build>
<finalName>myapp</finalName>
...
</build>

But I couldn't figure out how to change the base path for my views in this case. I should just have to prefix somehow the system with my "customz/dashboard" context path (?)

Does anybody, please, know how to get out of this trap?

NB: Spring Boot 2.2.8, Spring Cloud Hoxton.SR5, SBA 2.2.3, Tomcat 9.0.36


Solution

  • AdminServerUiAutoConfiguration declares resource handlers for the extensions (mapping context-path/extensions/** to the above classpath, as figured out when I tried to visualize custom JS and CSS earlier. Remember that spring.boot.admin.ui.extension-resource-locations default is classpath:/META-INF/spring-boot-admin-server-ui/extensions/ which seems fine in my case. That confirms that custom views are correctly exposed.

    So that leads us to spring-boot-admin-server-ui/src/main/frontend/index.html where all paths appear to be ... absolute!

    <th:block th:each="cssExtension : ${cssExtensions}">
        <link rel="preload" th:href="'/extensions/' + ${cssExtension.resourcePath}" as="style">
    </th:block>
    <th:block th:each="jsExtension : ${jsExtensions}">
        <link rel="preload" th:href="'/extensions/' + ${jsExtension.resourcePath}" as="script">
    </th:block>
    <th:block th:each="cssExtension : ${cssExtensions}">
        <link th:href="'/extensions/' + ${cssExtension.resourcePath}" rel="stylesheet">
    </th:block>
    <link rel="shortcut icon" th:href="${uiSettings.favicon}" type="image/png">
    <title th:text="${uiSettings.title}">Spring Boot Admin</title>
    ...
    <script lang="javascript" src="sba-settings.js"></script>
    <th:block th:each="jsExtension : ${jsExtensions}">
    <script lang="javascript" th:src="'/extensions/' + ${jsExtension.resourcePath}"></script>
    </th:block>
    

    I guess these are two points where both servlet and admin ui context paths should be added in order for extensions to be held. May be tehe quickest way would be to URls relative in index.html

    So I did exactly that... git cloning SBA on tag 2.2.3, doing the changes and Maven installing it, changing my server's parent to SNAPSHOT, then rebuilding the WAR into Tomcat. Et voilà.