Class SpringContextUtils
- Object
-
- org.thymeleaf.spring5.context.SpringContextUtils
-
public class SpringContextUtils extends Object
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
Fields Modifier and Type Field Description static StringWEB_SESSION_ATTRIBUTE_NAMEThis is the name of the model attribute that will hold the (asychronously resolved)WebSessionobject in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.context.ApplicationContextgetApplicationContext(org.thymeleaf.context.ITemplateContext context)Get theApplicationContextfrom the Thymeleaf template context.static IThymeleafRequestContextgetRequestContext(org.thymeleaf.context.IExpressionContext context)Get theIThymeleafRequestContextfrom the Thymeleaf context.
-
-
-
Field Detail
-
WEB_SESSION_ATTRIBUTE_NAME
public static final String WEB_SESSION_ATTRIBUTE_NAME
This is the name of the model attribute that will hold the (asychronously resolved)
WebSessionobject in order to be used whenever needed, avoiding the need to block for obtaining it from theServerWebExchange.Note resolving the
WebSessionfrom the reactiveMono<WebSession>stream does mean the creation of aWebSessioninstance, but not the real creation of a persisted session sent to the browser.Value:
"thymeleafWebSession"- See Also:
WebSession, Constant Field Values
-
-
Method Detail
-
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext(org.thymeleaf.context.ITemplateContext context)
Get the
ApplicationContextfrom 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 classThymeleafEvaluationContexthas been explicitly set into theITemplateContextcontextwith variable nameThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME.- Parameters:
context- the template context.- Returns:
- the application context, or
nullif it could not be accessed.
-
getRequestContext
public static IThymeleafRequestContext getRequestContext(org.thymeleaf.context.IExpressionContext context)
Get the
IThymeleafRequestContextfrom 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
-
-