加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

春天 – Thymeleaf Boot AngularJS指令解析器错误

发布时间:2020-12-17 09:17:07 所属栏目:安全 来源:网络整理
导读:这应该是一个容易的,但我找不到任何解决方案. 我在Jetty上使用Spring Boot 1.0.2与Thymeleaf支持我的AngularJS应用程序.但是,当使用attribute指令时,解析器会引发异常. 的pom.xml dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot
这应该是一个容易的,但我找不到任何解决方案.

我在Jetty上使用Spring Boot 1.0.2与Thymeleaf支持我的AngularJS应用程序.但是,当使用attribute指令时,解析器会引发异常.

的pom.xml

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.20</version>
    </dependency>

Thymeleaf配置

@Configuration
public class ThymeleafConfig {

@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("LEGACYHTML5");
    resolver.setCacheable(false);
    return resolver;
}

@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages");
    messageSource.setDefaultEncoding("UTF-8");

    return messageSource;
}
}

Thymeleaf正在工作,但它与属性指令有一个问题,像这样的Bootstrap UI示例:

<div class="btn-group" dropdown is-open="true">
            <button type="button" class="btn btn-primary dropdown-toggle">Button dropdown <span       class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
            </ul>
        </div>

我收到这个错误

org.xml.sax.SAXParseException: Attribute name "dropdown" associated with an element type "div" must be followed by the ' = ' character.

在哪里可以调整百里香,以接受这些属性?

– -编辑 – –

我为LEGACYHTML5添加了nekoHTML解析器,但仍然没有结果.

改变你的
@Bean
public ServletContextTemplateResolver templateResolver() { ... }

@Bean
public ServletContextTemplateResolver defaultTemplateResolver() { ... }

(注意默认).

在你的情况下,spring(引导)没有使用Thymeleaf的配置,所以你得到这个关于解析非标准属性的“奇怪”错误(因为默认的解析器是XHTML).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读