gpt4 book ai didi

saxparseexception - Thymeleaf v2.0.15 SaxParse 异常 - 扫描仪状态不是 24

转载 作者:行者123 更新时间:2023-12-04 09:02:10 24 4
gpt4 key购买 nike

我正在尝试使用 Thymeleaf 模板引擎在我的 Spring Web 应用程序中生成电子邮件。
我遵循了他们网站上的文档,但无论我的 HTML5 模板多么简单,我都会收到 SaxParseException。
我正在使用 HTML 5 模板,如下所示。

<!DOCTYPE html> 
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:remove="all">Account confirmation HTML email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h3 th:utext="#{mail.template.confirmation.greeting(${user.firstName}, ${user.lastName})}"></h3>
<p th:utext="#{mail.template.confirmation.introduction(${createdDate})}">
</p>
</body>
</html>

我的 Spring 配置。
@Bean
public ClassLoaderTemplateResolver emailTemplateResolver() {
ClassLoaderTemplateResolver cltr = new ClassLoaderTemplateResolver();
cltr.setPrefix("/dk/rfit/orderit/web/mail/");
cltr.setSuffix(".html");
cltr.setTemplateMode("HTML5");
cltr.setCharacterEncoding("UTF-8");
cltr.setOrder(3);
cltr.setCacheable(true);
return cltr;
}

@Bean
public TemplateEngine mailTemplateEngine() {
SpringTemplateEngine ste = new SpringTemplateEngine();
ste.setTemplateResolver(emailTemplateResolver());
return ste;
}

堆栈跟踪..
2013-01-31 08:01:33,431 [org.thymeleaf.TemplateEngine] [http-bio-8080-exec-10] (TemplateEngine.java:829) INFO  org.thymeleaf.TemplateEngine  - [THYMELEAF] INITIALIZING TEMPLATE ENGINE
2013-01-31 08:01:33,496 [org.thymeleaf.templateresolver.AbstractTemplateResolver] [http-bio-8080-exec-10] (AbstractTemplateResolver.java:99) INFO org.thymeleaf.templateresolver.AbstractTemplateResolver - [THYMELEAF] INITIALIZING TEMPLATE RESOLVER: org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
2013-01-31 08:01:33,496 [org.thymeleaf.templateresolver.AbstractTemplateResolver] [http-bio-8080-exec-10] (AbstractTemplateResolver.java:110) INFO org.thymeleaf.templateresolver.AbstractTemplateResolver - [THYMELEAF] TEMPLATE RESOLVER INITIALIZED OK
2013-01-31 08:01:33,498 [org.thymeleaf.messageresolver.AbstractMessageResolver] [http-bio-8080-exec-10] (AbstractMessageResolver.java:72) INFO org.thymeleaf.messageresolver.AbstractMessageResolver - [THYMELEAF] INITIALIZING MESSAGE RESOLVER: org.thymeleaf.spring3.messageresolver.SpringMessageResolver
2013-01-31 08:01:33,499 [org.thymeleaf.messageresolver.AbstractMessageResolver] [http-bio-8080-exec-10] (AbstractMessageResolver.java:78) INFO org.thymeleaf.messageresolver.AbstractMessageResolver - [THYMELEAF] MESSAGE RESOLVER INITIALIZED OK
2013-01-31 08:01:33,506 [org.thymeleaf.TemplateEngine.CONFIG] [http-bio-8080-exec-10] (ConfigurationPrinterHelper.java:130) INFO org.thymeleaf.TemplateEngine.CONFIG - [THYMELEAF] TEMPLATE ENGINE CONFIGURATION:
[THYMELEAF] * Cache Factory implementation: org.thymeleaf.cache.StandardCacheManager
[THYMELEAF] * Template modes:
[THYMELEAF] * LEGACYHTML5
[THYMELEAF] * VALIDXHTML
[THYMELEAF] * HTML5
[THYMELEAF] * XHTML
[THYMELEAF] * XML
[THYMELEAF] * VALIDXML
[THYMELEAF] * Template resolvers (in order):
[THYMELEAF] * [3] org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
[THYMELEAF] * Message resolvers (in order):
[THYMELEAF] * org.thymeleaf.spring3.messageresolver.SpringMessageResolver
[THYMELEAF] * Dialect: org.thymeleaf.spring3.dialect.SpringStandardDialect
[THYMELEAF] * Prefix: "th"
[THYMELEAF] TEMPLATE ENGINE CONFIGURED OK
2013-01-31 08:01:33,507 [org.thymeleaf.TemplateEngine] [http-bio-8080-exec-10] (TemplateEngine.java:842) INFO org.thymeleaf.TemplateEngine - [THYMELEAF] TEMPLATE ENGINE INITIALIZED
2013-01-31 08:09:52,146 [org.thymeleaf.TemplateEngine] [http-bio-8080-exec-10] (TemplateEngine.java:1173) ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][http-bio-8080-exec-10] Exception processing template "account-confirmation": Exception parsing document
2013-01-31 08:09:52,149 [dk.rfit.orderit.web.controller.AccountController] [http-bio-8080- exec-10] (AccountController.java:213) ERROR dk.rfit.orderit.web.controller.AccountController org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.parseTemplateUsingP ool(AbstractNonValidatingSAXTemplateParser.java:167) org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.parseTemplate(Abstr actNonValidatingSAXTemplateParser.java:115)
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:276)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1192)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1148)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1095)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1008)
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:982)



dk.rfit.orderit.web.service.EmailServiceThymeLeafImpl$1.prepare(EmailServiceThymeLeafImpl.java:65)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:352)
... 73 more
Caused by: org.xml.sax.SAXException: Scanner State 24 not Recognized
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1245 )
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:5 22)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.doParse(AbstractNon ValidatingSAXTemplateParser.java:208)
at org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.parseTemplateUsingP ool(AbstractNonValidatingSAXTemplateParser.java:132)
... 82 more

希望有人能告诉我该怎么做才能解决这个问题..

最佳答案

除了 Vel 的回答:如果您需要通过 utext 插入无效的 XHTML,这对于 HTML5 来说可能非常好(如未关闭的
标签),您需要使用模板模式 LEGACYHTML5:

cltr.setTemplateMode("LEGACYHTML5");

关于saxparseexception - Thymeleaf v2.0.15 SaxParse 异常 - 扫描仪状态不是 24,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14620984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com