Cannot access web context objects with thymeleaf in Spring boot project - spring

From looking at the thymeleaf documentation, I've tried to access web context objects with thymeleaf in my Spring boot project in this manner:
<p th:text="${#request.getRequestURL()}">lol</p>
which results in the following exception:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call:
Attempted to call method getRequestURL() on null context object
From this error it seems that I might be missing a dependency? I've seen a similar question, where the solution was to add an extras thymeleaf package as a dependency.
However, it is stated in the thymeleaf documentation that these objects and variable maps are always available to be invoked so I guess that shouldn't be the case here.
I'm using the release 1.5.1 of spring-boot-starter-thymeleaf as well as a number of other spring-boot-starter packages like web and security.

I got it to work with thymeleaf-spring4:3.0.0.RELEASE and thymeleaf-layout-dialect 2.0.0, so seems like these are the minimum versions required.
The spring-boot-starter-thymeleaf:1.5.1.RELEASE only provides thymeleaf-spring4:2.1.5.RELEASE and thymeleaf-layout-dialect 1.4.0.

Related

Springdoc-openapi. ClassNotFoundException: org.springframework.data.rest.webmvc.support.DefaultedPageable

After migration of Spring Boot to version 3.1 and springdoc-openapi libraries to 1.4.1:
springdoc-openapi-ui
springdoc-openapi-security
springdoc-openapi-data-rest
I faced issue ClassNotFoundException: org.springframework.data.rest.webmvc.support.DefaultedPageable
Also now on Swagger UI page controllers and schemas for #Entity are generated, however earlier there were only endpoints from #RestController, request and response DTOs. Are there any way to disable it?
From your description, you don't need to load springdoc-openapi-data-rest. (You will load unecessary beans related to spring-data-rest)
If you just need to enable the support of Pageable, you can just add the following line:
SpringDocUtils.getConfig().replaceWithClass(org.springframework.data.domain.Pageable.class, Pageable.class);
This is explained here: https://springdoc.org/
Section [Spring Data Rest support]
Or, if you want to depend on spring-boot-starter-data-rest, then add the dependency.

thymeleaf vs thymeleaf-spring4 dependency

Question is simple, what is the difference between the above dependencies? Does the first one enough for a springboot app or the second contains something special?
Artifact thymeleaf is the Core library.
Artifact thymeleaf-spring4 allows to integrate Thymeleaf with the Spring Framework, especially (but not only) Spring MVC. Btw there are several Thymeleaf integration packages for different Spring versions are available at the moment:
thymeleaf-spring3, thymeleaf-spring4, thymeleaf-spring5.
Information from thymeleaf-spring official documentation:
Thymeleaf offers a set of Spring integrations that allow you to use it as a fully-featured substitute for JSP in Spring MVC applications.
These integrations will allow you to:
Make the mapped methods in your Spring MVC #Controller objects forward to templates managed by Thymeleaf, exactly like you do with JSPs.
Use Spring Expression Language (Spring EL) instead of OGNL in your templates.
Create forms in your templates that are completely integrated with your form-backing beans and result bindings, including the use of property editors, conversion services and validation error handling.
Display internationalization messages from message files managed by Spring (through the usual MessageSource objects).
Resolve your templates using Spring’s own resource resolution mechanisms.
If you use Spring Boot, you can just use the spring-boot-starter-thymeleaf dependency. It already contains the above two dependencies as well as some others.

grails 3 spring security boot starter login page customization

Is it possible to customize the login gsp page for the starter security plugin?
org.springframework.boot:spring-boot-starter-security
I read about adding grails-app/views/login/auth.gsp but that made no difference.
If you are using Grails 3, then you probably would find it easier to use the Grails plugin, rather than trying to use the spring boot starter directly. In your gradle build, put:
compile 'org.grails.plugins:spring-security-core:<version>'
If you run the provided starter script, then the necessary grails config values will be placed in application.groovy for you to adjust to your needs. The docs for the plugin are quite good: https://grails-plugins.github.io/grails-spring-security-core/, and once you see how the plugin works, the Spring documentation becomes easier to use in the context of Grails (for example, all the spring bean config you might want to do based on Spring's docs you do in grails-app/conf/spring/resources.groovy using the bean builder DSL.
If you use this plugin then all the spring wiring will be done for you, and the override of the login page's gsp should work as advertised.
If you don't want to use the Grails plugin, then perhaps looking at the source for the plugin will give you the information you need to wire in the spring package yourself (since that's what the plugin does). Most of the spring wiring work takes place right in the plugin file SpringSecurityCoreGrailsPlugin.groovy

Jersey and Spring integration

I am developing a Jersey RESTful service using the Spring framework integration with Hibernate. I get a NoSuchMethodException on a org.jboss.logging.logger.debugf call. As I noticed, the class is indeed loaded from the bean-validator.jar included alongside the jersey-spring3 library, eventhough I have specifically referenced the jboss logging artifact.
Has anyone encountered this issue? And if so, how should I solve it?
Update
I have found a workaround, but it is far from being a solution. In order for the required classes to have the same signature, I have downgraded the hibernate-entitymanager to version 4.2.8.Final. However, this leads the way to other compatibility issues.
Update 2
In the end, I have chosen to implement the REST service functionality using the Spring Framework instead of using the aforementioned integration.
Check out the answers in the following post, your issue might be similar:
Error "java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger"

Equivalent of org.springframework.boot.context.embedded.FilterRegistrationBean for non-Boot Spring project?

I'm trying to implement external session handling in Spring, as per this tutorial. I'm having some trouble adding the right filter though. Spring Boot appears to have defined the proper bean/filter, but my project is not Spring Boot, so it cannot find the FilterRegistrationBean. Is there some sort of equivalent to this class in non-Boot versions of Spring? I also tried org.springframework.web.context.embedded.FilterRegistrationBean, but can't get it to import properly (it looks like this documentation refers to a SNAPSHOT version, so perhaps this package was never part of a proper release).
Depending on your container configuration, web.xml or ServletContainerInitializer, you can register a DelegatingFilterProxy filter and make it refer, by name, to a Filter bean you've declared in your ApplicationContext.

Resources