Class SpringContextUtils
Utility class for easy access of information stored at the context in a Spring-enabled application (such as the Spring ApplicationContext).
- Since:
- 3.0.3
- Author:
- Daniel Fernández
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
This is the name of the model attribute that will hold the (asychronously resolved)Principal
object in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange
.static final String
This is the name of the model attribute that will hold the (asychronously resolved)WebSession
object in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange
. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.context.ApplicationContext
getApplicationContext
(ITemplateContext context) Get theApplicationContext
from the Thymeleaf template context.static IThymeleafRequestContext
getRequestContext
(IExpressionContext context) Get theIThymeleafRequestContext
from the Thymeleaf context.
-
Field Details
-
WEB_SESSION_ATTRIBUTE_NAME
This is the name of the model attribute that will hold the (asychronously resolved)
WebSession
object in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange
.Note resolving the
WebSession
from the reactiveMono<WebSession>
stream does mean the creation of aWebSession
instance, but not the real creation of a persisted session sent to the browser.Value:
"thymeleafWebSession"
- See Also:
-
WebSession
- Constant Field Values
-
WEB_EXCHANGE_PRINCIPAL_ATTRIBUTE_NAME
This is the name of the model attribute that will hold the (asychronously resolved)
Principal
object in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange
.Value:
"thymeleafWebExchangePrincipal"
- Since:
- 3.1.0
- See Also:
-
ServerWebExchange
Principal
- Constant Field Values
-
-
Method Details
-
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext(ITemplateContext context) Get the
ApplicationContext
from the Thymeleaf template context.Note that the application context might not be always accessible (and thus this method can return
null
). Application Context will be accessible when the template is being executed as a Spring View, or else when an object of classThymeleafEvaluationContext
has been explicitly set into theITemplateContext
context
with variable nameThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME
.- Parameters:
context
- the template context.- Returns:
- the application context, or
null
if it could not be accessed.
-
getRequestContext
Get the
IThymeleafRequestContext
from the Thymeleaf context.The returned object is a wrapper on the Spring request context that hides the fact of this request context corresponding to a Spring WebMVC or Spring WebFlux application.
This will be done by looking for a context variable called
SpringContextVariableNames.THYMELEAF_REQUEST_CONTEXT
.- Parameters:
context
- the context- Returns:
- the thymeleaf request context
-