Spring的新功能 - 使用sec标签无效

时间:2017-03-17 02:22:24

标签: java spring jsp spring-mvc

您好我正在为一个项目学习Spring,并且我正在尝试自己创建sec标签,以便在不同用户登录时创建多个视图。我一直在设置标签时遇到错误。

这是我的JSP:

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

<html>
<head>
<title>Welcome</title>
</head>
<body>
    <h1>Welcome</h1>
    <security:authorize access="hasRole('admin')">
    Only admins can see the <a href="second">Second link</a>
    </security:authorize>
</body>
</html>

出现错误:无法找到“http://www.springframework.org/security/tags

的标记库描述符

这是我的xml:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-4.0.xsd
    ">



    <mvc:annotation-driven />

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <!-- Filter for role checking -->
<bean id="filterSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
    <property name="authenticationManager" ref="authenticationManager"/>
    <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/>
    <property name="securityMetadataSource">
        <security:filter-security-metadata-source lowercase-comparisons="true" request-matcher="ant" use-expressions="true">
            <security:intercept-url pattern="/pages/Security/**" access="permitAll"/>
            <security:intercept-url pattern="/resources/**" access="permitAll"/>
            <security:intercept-url pattern="/pages/Settings/**" access="hasRole('SETTINGS')"/>
            <security:intercept-url pattern="/pages/Home/*" access="hasRole('HOME')"/>              
            <security:intercept-url pattern="/pages/Admin/**" access="hasRole('ADMINISTRATOR')"/>
            <security:intercept-url pattern="/servlet/Download" access="hasAnyRole('DOWNLOAD','PREMIUM_ACCOUNT')"/>

            <security:intercept-url pattern="/**" access="isAuthenticated()"/>
        </security:filter-security-metadata-source>
    </property>
</bean>

<!-- webInvocationPrivilegeEvaluator necessary to use <sec:authorized url="xx"> -->
<bean id="webInvocationPrivilegeEvaluator" class="org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator">
    <constructor-arg ref="filterSecurityInterceptor"></constructor-arg>
</bean>

</beans>

我来回切换“秒”到“安全”和其他一些东西,但无法让它工作。提前感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

spring-security-taglibs-3.1.3.release.jar 添加到项目的类路径中。

如果您使用 Maven ,请在pom.xml中添加此依赖项

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