如何使百万美元弹簧安全命名空间可用?

时间:2015-10-02 23:35:39

标签: java maven spring-mvc spring-boot thymeleaf

我有一个Spring Boot应用程序。根据我的理解,启动应用程序只需要pom中的依赖项,一切都很棒。不幸的是,情况并非如此,即使我的配置过于复杂,它仍然不起作用 - 我不能在我的页面中使用sec命名空间。

在我的页面中,第一个问题是命名空间URI:

enter image description here

我已经尝试了Intellij修复菜单中的所有选项,但无法获得它。

我认为该问题的结果是我无法在任何地方使用sec命名空间。图示的例子可能确实是无效的用法,但我也使用了<div>,它直接来自Thymeleaf的例子:

enter image description here

这里的许多答案和其他来源也依赖于xml配置,这是没有用的。尽管如此,我还是基于这些xml示例创建了基于Java的bean,但没有运气。

在仅使用基于Java的配置(如果是)的情况下,在spring boot应用程序中使用spring security和thymeleaf集成需要哪些步骤?

的pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>2.1.2.RELEASE</version>
    </dependency>
    ...
</dependencies>

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,对我而言,它有助于定义这样的架构位置:

<html lang="en"
  xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.thymeleaf.org http://www.thymeleaf.org
  http://www.ultraq.net.nz/thymeleaf/layout http://www.ultraq.net.nz/thymeleaf/layout
  http://www.thymeleaf.org/thymeleaf-extras-springsecurity4 http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

...

这还包括布局和弹簧安全4的附加方言,如果您不使用它们,可以删除。