错误“试图访问私有字段 org.thymeleaf.standard.StandardDialect.conversionService”将 thymeleaf-spring5 升级到 3.0.15.RELEASE
我的 Spring boot 版本是 2.3.12.RELEASE thymeleaf 版本:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.15.RELEASE</version>
</dependency>
之前工作的 thymeleaf 版本是 3.0.11.RELEASE
这是我的代码:
class HtmlGenerationService {
private static final String CONTEXT_ROOT_VARIABLE = "ctx";
private static final long CACHE_TTL_MS = 86_400_000L;
private final SpringTemplateEngine templateEngine;
public HtmlGenerationService () {
ClassLoaderTemplateResolver classPathResolver = new ClassLoaderTemplateResolver();
classPathResolver.setPrefix(PdfConfig.PDF_TEMPLATE_SUB_DIRECTORY + "/");
classPathResolver.setSuffix(".html");
classPathResolver.setTemplateMode("HTML");
classPathResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
classPathResolver.setCacheable(true);
classPathResolver.setCacheTTLMs(CACHE_TTL_MS);
templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolvers(new HashSet<>(Arrays.asList(classPathResolver)));
}
String createCoversheet(CoversheetDto coversheet) {
Context context = new Context();
context.setVariable(CONTEXT_ROOT_VARIABLE, coversheet);
return templateEngine.process("cover", context);
}
}
这是堆栈:
java.lang.IllegalAccessError: class org.thymeleaf.spring5.dialect.SpringStandardDialect tried to access private field org.thymeleaf.standard.StandardDialect.conversionService (org.thymeleaf.spring5.dialect.SpringStandardDialect and org.thymeleaf.standard.StandardDialect are in unnamed module of loader 'app')
at org.thymeleaf.spring5.dialect.SpringStandardDialect.getConversionService(SpringStandardDialect.java:295)
at org.thymeleaf.standard.StandardDialect.getExecutionAttributes(StandardDialect.java:397)
at org.thymeleaf.spring5.dialect.SpringStandardDialect.getExecutionAttributes(SpringStandardDialect.java:323)
at org.thymeleaf.DialectSetConfiguration.build(DialectSetConfiguration.java:263)
at org.thymeleaf.EngineConfiguration.<init>(EngineConfiguration.java:123)
at org.thymeleaf.TemplateEngine.initialize(TemplateEngine.java:336)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1079)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1059)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1048)
My Spring boot version is 2.3.12.RELEASE
thymeleaf version:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.15.RELEASE</version>
</dependency>
the previous working thymeleaf verison is 3.0.11.RELEASE
here is my code:
class HtmlGenerationService {
private static final String CONTEXT_ROOT_VARIABLE = "ctx";
private static final long CACHE_TTL_MS = 86_400_000L;
private final SpringTemplateEngine templateEngine;
public HtmlGenerationService () {
ClassLoaderTemplateResolver classPathResolver = new ClassLoaderTemplateResolver();
classPathResolver.setPrefix(PdfConfig.PDF_TEMPLATE_SUB_DIRECTORY + "/");
classPathResolver.setSuffix(".html");
classPathResolver.setTemplateMode("HTML");
classPathResolver.setCharacterEncoding(StandardCharsets.UTF_8.name());
classPathResolver.setCacheable(true);
classPathResolver.setCacheTTLMs(CACHE_TTL_MS);
templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolvers(new HashSet<>(Arrays.asList(classPathResolver)));
}
String createCoversheet(CoversheetDto coversheet) {
Context context = new Context();
context.setVariable(CONTEXT_ROOT_VARIABLE, coversheet);
return templateEngine.process("cover", context);
}
}
Here is the stack:
java.lang.IllegalAccessError: class org.thymeleaf.spring5.dialect.SpringStandardDialect tried to access private field org.thymeleaf.standard.StandardDialect.conversionService (org.thymeleaf.spring5.dialect.SpringStandardDialect and org.thymeleaf.standard.StandardDialect are in unnamed module of loader 'app')
at org.thymeleaf.spring5.dialect.SpringStandardDialect.getConversionService(SpringStandardDialect.java:295)
at org.thymeleaf.standard.StandardDialect.getExecutionAttributes(StandardDialect.java:397)
at org.thymeleaf.spring5.dialect.SpringStandardDialect.getExecutionAttributes(SpringStandardDialect.java:323)
at org.thymeleaf.DialectSetConfiguration.build(DialectSetConfiguration.java:263)
at org.thymeleaf.EngineConfiguration.<init>(EngineConfiguration.java:123)
at org.thymeleaf.TemplateEngine.initialize(TemplateEngine.java:336)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1079)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1059)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1048)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论