Thymeleaf v2.0.15 SaxParse Exception - 扫描仪状态不是24

时间:2013-01-31 07:59:02

标签: saxparseexception thymeleaf

我正在尝试使用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;
}   

StackTrace ..

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

希望有人能告诉我该如何解决这个问题。

3 个答案:

答案 0 :(得分:1)

除了Vel的回答:如果你需要通过utext插入无效的XHTML,这对HTML5来说非常好(比如unclosed&lt; br&gt;标签),你需要使用模板模式LEGACYHTML5:

cltr.setTemplateMode("LEGACYHTML5");

答案 1 :(得分:0)

当解析的标记不是格式良好的XML时,解析器通常会引发此错误。 解析后,html5模板文件不是有效的html文件。这意味着某些结束标记(/&gt;)或某些额外标记不符合XHTML的验证。

答案 2 :(得分:0)

另一种选择是在def concatenate(arrs, axis=0): dest = 'dimensionless' for a in arrs: if hasattr(a, 'units'): dest = a.units break data = [] for a in arrs: if hasattr(a, 'to'): a = a.to(dest).magnitude data.append(np.atleast_1d(a)) return units.Quantity(np.concatenate(data, axis=axis), dest) 中指定属性:

const response1 = { nested: { obj: { 'b': 2 } }};
const response2 = { nested: { obj: { 'a': 2 } }};

const merge1 = _.merge({}, response1, response2);
console.log(merge1); // { nested: { obj: { b: 2, a: 2 } } }


const response3 = { nested: { obj: { 2: 2 } }};
const response4 = { nested: { obj: { 1: 1 } }};

const merge2 = _.merge({}, response3, response4);
console.log(merge2); // { nested: { obj: { '1': 1, '2': 2 } } }

在您的项目中具有application.properties依赖关系,例如在spring.thymeleaf.mode=LEGACYHTML5

nekohtml

是强制性的。