xdh*_*ore 24 spring thymeleaf spring-boot
我正在使用Spring Boot,我想添加IE条件评论Thymeleaf方言.
我把它包含在我的maven pom.xml中,但它不起作用.我如何告诉Thymeleaf使用它?
xdh*_*ore 31
注意:在尝试此操作之前,请注意,Spring Boot的更高版本包含一些开箱即用的常用方言.请参阅@Robert Hunt的回答.除此以外:
有一个例子在这里加入方言豆类,其中春季启动会自动检测并使用(见LayoutDialect代码和ThymeleafDefaultConfiguration类的方言成员)的.在您的情况下,在其中一个@Configuration
类中添加以下内容:
@Bean
public ConditionalCommentsDialect conditionalCommentDialect() {
return new ConditionalCommentsDialect();
}
Run Code Online (Sandbox Code Playgroud)
Spring引导,在ThymeleafAutoConfiguration类中,将自动添加任何实现IDialect接口的Bean.
Rob*_*unt 13
随着Spring Boot 1.2.1的发布,ThymeleafAutoConfiguration类中添加了一些额外的方言,如果它们位于类路径上,将自动检测,包括:
只需在类路径上使用JAR就足以让Spring Boot注册它们.
注意:如果您正在使用,spring-boot-starter-thymeleaf
那么您会发现默认情况下已包含LayoutDialect.
小智 5
我实际上认为ThymeleafAutoConfiguration存在缺陷.我看到它应该拾取的代码并将SpringSecurityDialect添加到Config,如果它在类路径上,但在我的调试中,这根本不会发生(只有LayoutDialect被定向并添加到配置中).我的classpath上有SpringSecurityDialect类/ jar,但是下面的bean永远不会被SpringBoot AutoConfig添加到配置中(ThymeleafAutoConfig.java,第97行)
@Configuration
@ConditionalOnClass({SpringSecurityDialect.class})
protected static class ThymeleafSecurityDialectConfiguration {
protected ThymeleafSecurityDialectConfiguration() {
}
@Bean
@ConditionalOnMissingBean
public SpringSecurityDialect securityDialect() {
return new SpringSecurityDialect();
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我必须实际将bean添加到我的自定义Java配置中以获得SpringSecurityDialog:
@Bean
public SpringSecurityDialect securityDialect() {
return new SpringSecurityDialect();
}
Run Code Online (Sandbox Code Playgroud)
这是第一次工作.您是否可以通过一些测试来验证这是一个已知问题?我包括我的pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17936 次 |
最近记录: |