How to fix this springboot ErrorPageFilter error? - spring-boot

It's a simple web application use external tomcat-9.0.56 and spring 5.3, springboot 2.5.5 and up, which works on windows 10 but not on ubuntu 18. It always display 404 because of the ErrorFilterPage.
The tomcat used Context to point to the folder where the webapp was located at, also virtual host in apache 000-default.conf
I've tried set setRegisterErrorPageFilter(false); or in the application.properties as well as inject #Bean FilterRegistrationBean disableSpringBootErrorFilter with/without return new ErrorPageFilter(); in #Bean public ErrorPageFilter errorPageFilter(), no success.
I feel despair at such a framework that can not deploy to Ubuntu with delays and disappointment that cause me a lot.
It's just a simple hello: http://localhost:8080/home:
https://drive.google.com/file/d/1BiJ4-E0nPjuh1YxREpOcwN4AlzdSe3Pu/view?usp=sharing
How to fix it?!

There's a typo in your application.properties file where you have configured spring.mvc.view.prefix. The value has a trailing space. It is /WEB-INF/views/ and should be /WEB-INF/views/. With this change in place, the /hello endpoint works:
$ curl localhost:8080/hello
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>SAMPLE</title>
</head>
<body>
HELLO SPRING!
</body>
</html>%
Spring Boot intentionally does not trim whitespace from property values as there's no way for it to know whether or not the whitespace is intentional.

Related

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

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.

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.

Spring Controller request parameter wrong encoding in one instance of Tomcat but not the others

I have a Spring MVC application which works fine in eclipse (local tomcat instance) and in a test environment where tomcat is installed as a service. But when I deploy the application in production the request parameters are not parsed correctly (Greek characters).
My server.xml configuration file in production (and in both local and test envirnonments) has the URIEncoding="utf-8" attribute on all connector elements.
I have set the CharacterEncodingFilter in web.xml.
My Jsp pages have all the
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and
<%#page contentType="text/html" pageEncoding="UTF-8"%>
What else could be different between these Tomcat instances?
The only thing I can think off is the regional settings on windows but I hope this does not affect this?

Resources