(WAR) Spring Boot Admin custom view not found - spring-boot

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

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Ă .

Related

Spring Boot 2.0 Static content not using context path

I have a Spring Boot 2.0 application that I'm trying to deploy as a WAR file. This means that it will have a custom context path. To test as a Java application I added
server.servlet.context-path=/MyApplication
to the application.properties. In my index.html (located in src/main/resources/static) I try to include Javascript using something like this:
<script src="dist/main.js"</script>
Regardless of whether I am using the context path, this always tries to load the file from http://localhost:8080/dist/main.js completely ignoring the context path I have specified. The same is true if I try to deploy my application as a WAR. The file is really at http://localhost:8080/MyApplication/dist/main.js.
What do I need to change in my configuration to make Spring Boot use the context path when serving static content?
I just figured it out. In my index.html I had set a base href:
<base href="/">
I converted index.html to a JSP and set the base href using a JSP tag:
<base href='<c:url value="/" />'>
Modify the <base href="/"> in index.html to the following,
<base href="./">
This will try to load all the scripts from the context path that is specified and it fixed the issue for me.

Spring Boot Security + GWT, static resources access 403 error

I am fighting the css/js access problem in my gwt+spring security simple application. So, i have secutiy controller with the next method:
#GetMapping(value = "/notes")
public ModelAndView index(ModelAndView modelAndView) {
modelAndView.setViewName(VIEW_NOTES);
return modelAndView;
}
By the way, I integrated these technologies according to this article. So, thanks to this controller method (I use RestController) we've got resolved view (simple as ****):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Notes</title>
<link rel="stylesheet" type="text/css" media="all"
href="../static/css/notes-main.css"></link>
</head>
<body>
<!-- This script tag is what actually loads the GWT module. The -->
<!-- 'nocache.js' file (also called a "selection script") is -->
<!-- produced by the GWT compiler in the module output directory -->
<!-- or generated automatically in development mode. -->
<script language="javascript" src="notesgwtapp/notesgwtapp.nocache.js">
</script>
<!-- Include a history iframe to enable full GWT history support -->
<!-- (the id must be exactly as shown) -->
<iframe src="javascript:''" id="__gwt_historyFrame"
style="width:0;height:0;border:0"></iframe>
<div id="notes"></div>
</body>
</html>
Now is the most interesting thing that I have these two errors:
GET http://localhost:8080/static/css/notes-main.css 403
GET http://localhost:8080/notesgwtapp/notesgwtapp.nocache.js 403
I dont have problems with resolving resources for other views, btw.
Please help, how can I handle it? If i miss some important part of code, I will add it. Just ask. Thank you in advance.
By default Sprint Boot permits all access to /js/**, /css/**, /images/**. But you try to access /static/** and /notesgwtapp/** which will result in the 403 error (see here).
There are two solutions:
Make sure that the notesgwtapp.nocache.js and the notes-main.css file end up in one of the above folders or
Override the SecurityConfig of your Spring Boot app and add the /static/** and /notesgwtapp/** folder to the permitted locations.

Referencing css and js files in bootstrap

I am trying to reference to my css files as shown in the image. Since my index.html is in the templates folder, i have to go back 1 level up(../), and then go into static/css/{the file that i want}. However, this fails to render my css and js files. What am i doing wrong here? I am using thymelead templating engine for this spring boot application. Please help thank you
Spring-Boot and Thymeleaf works well together. By default Spring-Boot look up for static resources in those folders.
/META-INF/resources
/resources/
/static/
/public/
So you dont need to go back to any upper level. Your reference should normally work like that:
<link rel="stylesheet" href="/css/bootstrap.min.css" th:href="#{/css/bootstrap.min.css}" />

Thymeleaf th:include doesn't work after update to Spring Boot 1.3

I have an application which works fine with Spring Boot 1.2.6. Now I tried to 1.3.5 and have the problem, that the following statement doesn't work anymore:
<head >
<title th:text="#{app.title} + ' - ' + #{login.title}"></title>
<th:block th:include="main::head"/>
</head>
I can see in the Thymeleaf log that the main.html is found. Furthermore the Thymeleaf-Expressions from the head are evaluated. How ever the html in the browser has no content in head, neither title nor the content from main.html.
As far as I can see the Thymeleaf version hasn't changed.
So what can be the reason?
The version of the Layout dialect has changed. So I added the property <thymeleaf-layout-dialect.version>1.2.9</thymeleaf-layout-dialect.version> to my pom.xml and everything was fine.
I created an issue for that.

How to make spring mvc app run under a sub folder

I was only testing my spring-mvc as a root app on top of tomcat 7.0.50, now however I need to run at under a subfolder of the domain, like www.blabla.com/myapp
Unfortunately it does not work: all the resource files are missing and the application tries to redirect itself to root all the time.
How do i configure a spring mvc application to run under a subfolder?
I think it depends on your configuration of your HTTP Server (Apache, Nginx) and it has nothing to do with Spring.
The basic problem was that all references (including form actions) in jsp pages are absolute (a least with my current configuration) and I had to c:url them.
static resources:
<link href="<c:url value="/resources/css/bootstrap.css"/>" rel="stylesheet" type="text/css"/>
form actions:
<c:url var="proceedActionUri" value="/user/mainscreen"/>
<form:form method="post" action="${proceedActionUri}" commandName="user" role="form">

Resources