找不到 Spring Security 标记库

Posted

技术标签:

【中文标题】找不到 Spring Security 标记库【英文标题】:Spring Security taglib cannot be found 【发布时间】:2013-04-12 13:33:12 【问题描述】:

当我把<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

我会收到以下错误:

The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application

但我的 /lib 文件夹中有 spring-security-taglibs-3.1.3 等。有谁知道我还缺少什么?

【问题讨论】:

你在 web.xml 上启动 SpringSecurity 监听了吗? 【参考方案1】:

添加此依赖项为我修复了它(使用 3.1.X.RELEASE):

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

标签库现在可以正常工作了:

&lt;%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %&gt;

【讨论】:

是的,但我应该选择哪个版本?【参考方案2】:

确保包含以下依赖项

<dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.1.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.1.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.1.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>3.1.3.RELEASE</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>

【讨论】:

【参考方案3】:

我正在使用 jetty 9 (jetty-maven-plugin) 以上帮不上忙。所以将下面的代码添加到 WEB-INF/web.xml 中,它就像魅力一样工作:

<servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspf</url-pattern>
        <url-pattern>*.jspx</url-pattern>
        <url-pattern>*.xsp</url-pattern>
        <url-pattern>*.JSP</url-pattern>
        <url-pattern>*.JSPF</url-pattern>
        <url-pattern>*.JSPX</url-pattern>
        <url-pattern>*.XSP</url-pattern>
    </servlet-mapping>

另外添加到jetty-context.xml中问题依旧:

<Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
        <Arg>^$|.*/spring-[^/]*\.jar$|</Arg>
    </Call>
</Configure>

【讨论】:

以上是关于找不到 Spring Security 标记库的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu 安装MySQL报共享库找不到

c++文件中jni库找不到报红

.netcore类库找不到main函数

Spring Security 找不到数据源

Spring Security 找不到 NamespaceHandler

添加“spring-security-taglibs”后jsp中仍然报错:找不到spring security标签的标签库描述符