【问题标题】:Spring Boot 2 -- security taglibs not found, wrong taglib version in the java jspSpring Boot 2 - 未找到安全标签库,java jsp 中的标签库版本错误
【发布时间】:2018-07-30 16:33:04
【问题描述】:

我知道有很多类似的问题,但我似乎找不到 Spring Boot 2 的答案。我收到了这个错误:

Caused by: org.apache.jasper.JasperException: The absolute uri: [http://www.springframework.org/security/tags] 
cannot be resolved in either web.xml or the jar files deployed with this application

于是我查看了/work目录,找到了jsp的java,发现这一行:

_jspx_dependants.put("/WEB-INF/lib/spring-security-taglibs-3.2.0.RELEASE.jar", Long.valueOf(1524843694000L));

现在我的 pom 在 spring-security-taglibs-5.0.6.RELEASE.jar 中有它,它位于 /lib 目录中。

我也在使用 apache tile 3.0.5。不知道这是否重要。

这是我的 pom 条目:

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
        </exclusion>
    </exclusions>       
</dependency>

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

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-taglibs</artifactId>
</dependency>   

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-messaging</artifactId>
</dependency>   

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

<!--  Tiles -->
<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-jsp</artifactId>
    <version>${apache.tiles.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-core</artifactId>
    <version>${apache.tiles.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-api</artifactId>
    <version>${apache.tiles.version}</version>
    <scope>compile</scope>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-servlet</artifactId>
    <version>${apache.tiles.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.tiles</groupId>
    <artifactId>tiles-template</artifactId>
    <version>${apache.tiles.version}</version>
</dependency>

知道该版本是如何进入 jsp 的 java 的吗?

更新 我不再认为这是 Spring Boot 2 的问题。我恢复到启动 1.5.15,我得到了同样的错误。我什至进一步回到了一个简单的 spring 项目(4.3.18.RELEASE 和 spring-security 4.2.7.RELEASE),我得到了同样的错误。但是,如果我一直恢复到 spring security 3.2.0,它就可以工作。

我一定是某个地方存在依赖冲突,或者旧的安全版本包含 4.x 没有的依赖。

我还发现也找不到常规的spring标签。即:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> 

抛出一个关于找不到http://www.springframework.org/tags 的错误,如果我切换“spring”和“sec”的顺序,我会得到标签库是第一个的错误。但是——我没有收到http://java.sun.com/jsp/jstl/core 的错误,所以这不是一般的“加载标签库”错误。

【问题讨论】:

  • 我会在 Eclipse 中查看您的 pom.xml 的依赖层次结构,看看您的任何依赖项是否引入了比您打算使用的更早版本的 Spring。
  • 如果您尝试构建单 jar 工件,则可能存在打包应用程序的问题。这个答案可能会有所帮助:stackoverflow.com/questions/51718271/… - 这是我使用 Maven shade 构建单 jar 工件的方式,为我的所有依赖项保留正确的元数据文件。
  • 我查看了层次结构,以及战争的WEB-INF/lib文件夹,它并没有引入旧版本。另外,我不认为这是一个包装问题,因为我所要做的就是将 spring-secrutiy 版本更改为 3.x 并且它可以工作。
  • 有没有运行mavens依赖树看有没有警告:mvn dependency:tree?

标签: spring spring-security jsp-tags apache-tiles


【解决方案1】:

当我使用 2.1.3 版本的 Spring Boot 配置 Spring Security 时,我遇到了同样的问题。不知道为什么会这样。

spring security boot 版本不会添加tablib库。如果是在jsp中使用,则必须手动添加。

在你的 pom.xml 文件中添加这一行,它就解决了依赖关系。

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId></dependency>

希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2012-11-21
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 2017-10-16
    • 2015-12-02
    • 2011-01-16
    相关资源
    最近更新 更多