![](/img/trans.png)
[英]Spring Boot + Thymeleaf + Dandelion configuration not working
[英]Default Spring Boot Thymeleaf configuration location
我已经使用 JSP 很久了,但直到现在我才尝试使用 Thymeleaf。 我发现对于我的应用程序,我需要对我的application.properties
文件添加一些调整,并且我已经找到了要使用的 Spring Boot Thymeleaf 设置。
但是我在哪里可以找到 Spring Boot 默认使用的权威的、完整的 Thymeleaf 设置列表? 例如,我知道 Spring Boot 将 Thymeleaf 配置为在类路径上的/templates/
目录中查找模板,并且我知道如何更改它。 但是默认的/templates/
在哪里配置? 是否有我可以打开的DefaultXXX
类或.properties
文件以查看这些文件是如何设置的以及如果我不进行任何更改会使用哪些值?
有属性设置列表在这里-你可以搜索页面“thymeleaf”,找到相关部分。
例子:
Key Default Value Description
spring.thymeleaf.prefix classpath:/templates/ Prefix that gets prepended to view names when building a URL.
此示例显示,对于 Thymeleaf ClassLoaderTemplateResolver
使用默认值/templates/
(如您所述)。
我不知道它是否是权威的完整列表 - 但它看起来相当全面,基于我通常希望在非 Spring Thymeleaf 实现中设置的设置。
更新
要添加更多详细信息,请查看文档中的两个示例:
示例 1: spring.thymeleaf.cache
- 默认为true
对于此值,默认值在AbstractConfigurableTemplateResolver类中定义:
public static final boolean DEFAULT_CACHEABLE = true;
这是GitHub 上源代码的链接。
示例 2: spring.thymeleaf.prefix
- 默认为classpath:/templates/
在这种情况下,有一个 Spring 类可以处理这个(以及许多其他)默认值: org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties
例如前缀示例:
public static final String DEFAULT_PREFIX = "classpath:/templates/";
还值得注意的是,上面示例 1 中的cache
设置也在 Spring ThymeleafProperties
类中显式设置。
补充说明
反应设置还有一些属性:
spring.thymeleaf.reactive.max-chunk-size
- 默认为0B
这是在嵌套的Reactive
类中设置的:
private DataSize maxChunkSize = DataSize.ofBytes(0);
上述位置仍然不是 100% 全面。 例如:
spring.thymeleaf.enable-spring-el-compiler
根据文档设置为false
。 在源代码中,它是隐式错误的:
private boolean enableSpringElCompiler;
但这并不能告诉您可能的编译器设置是什么,如果您选择将此属性设置为true
(请参阅此处)。
关于属性文件的说明
我不知道用作此 Thymeleaf 配置过程的一部分的任何默认属性文件或属性文件模板。 我的理解是,如果您想自定义这些设置,并且您还没有 Spring 属性文件,则必须自己创建它 - 但我可能会误会。
附加说明 2
以DEFAULT_PREFIX
为例:这是由ThymeleafAutoConfiguration
类( 此处)处理的。 这会在SpringResourceTemplateResolver
类中设置前缀,该类是 Thymeleaf 的 Spring 集成模块的一部分(来源在这里)。
resolver.setPrefix(this.properties.getPrefix());
这个解析器“使用 Spring 的资源解析机制解析模板”——这是我的研究停滞的地方。
关于默认前缀和spring.thymeleaf.prefix
提供的值的关系,我看到的直接连接的唯一位置是这里,它调用一个PropertyResolver方法返回用户提供的属性值,否则为默认值,除此以外。 但同样,这仅用于验证模板是否可以被定位(而不是实际被检索)——所以这当然不是全貌。 同样,这是我的研究停滞的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.