错误“试图访问私有字段 org.thymeleaf.standard.StandardDialect.conversionService”将 thymeleaf-spring5 升级到 3.0.15.RELEASE

发布于 2025-01-13 09:09:39 字数 2569 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文