添加springsecurity.taglib.xml时无法运行项目

时间:2012-05-18 01:50:51

标签: spring security jsf spring-security glassfish

我在实现spring security和jsf 2.0时遇到问题,正好在web.xml中添加springsecurity.taglib.xml时

服务器:glassfish服务器3
springframework 3.0.2
jsf 2.0

图书馆:
org.springframework.faces.sources 3

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"          xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>HelloWorldExampleWithSpring3MVCInEclipse</display-name>
<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/app-config.xml</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/app-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
    <welcome-file>faces/index.jsp</welcome-file>
</welcome-file-list>

springsecurity.taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
 "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.springframework.org/security/tags</namespace>
<tag>
    <tag-name>authorize</tag-name>
    <handler-class>org.springframework.faces.security.FaceletsAuthorizeTagHandler</handler-class>
</tag>
<function>
    <function-name>areAllGranted</function-name>
    <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
    <function-signature>boolean areAllGranted(java.lang.String)</function-signature>
</function>
<function>
    <function-name>areAnyGranted</function-name>
    <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
    <function-signature>boolean areAnyGranted(java.lang.String)</function-signature>
</function>
<function>
    <function-name>areNotGranted</function-name>
    <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
    <function-signature>boolean areNotGranted(java.lang.String)</function-signature>
</function>
<function>
    <function-name>isAllowed</function-name>
    <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class>
    <function-signature>boolean isAllowed(java.lang.String, java.lang.String) </function-signature>
</function>
</facelet-taglib>

这是错误消息

In-place deployment at D:\Project\Secret Project\Hobic Project EE\Yeah\build\web
deploy?path=D:\Project\Secret Project\Hobic Project     EE\Yeah\build\web&name=Yeah&force=true failed on GlassFish Server 3
D:\Project\Secret Project\Hobic Project EE\Yeah\nbproject\build-impl.xml:760: The module has not been deployed.
BUILD FAILED (total time: 1 minute 29 seconds)

服务器错误消息

SEVERE: Exception while loading the app
SEVERE: Exception while loading the app : java.lang.IllegalStateException:    ContainerBase.addChild: start: org.apache.catalina.LifecycleException:   java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: 
Source Document:     jar:file:/D:/Project/Secret%20Project/Hobic%20Project%20EE/Zest/build/web/WEB-  INF/lib/org.springframework.faces-2.0.4.RELEASE.jar!/META-INF/faces-config.xml
Cause: Class 'org.springframework.faces.webflow.FlowActionListener' is missing a  runtime dependency: java.lang.NoClassDefFoundError:  org/springframework/webflow/execution/RequestContext

你的建议正确 [java.lang.NoClassDefFoundError:org / springframework / webflow / execution / RequestContext],我现在收到了新的错误:(

SEVERE: Exception while loading the app
SEVERE: Exception while loading the app : java.lang.IllegalStateException:  ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [security.xml]
Offending resource: ServletContext resource [/WEB-INF/app-config.xml]; nested exception    is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/security.xml]

* 解决方案[Offending resource:ServletContext resource [/WBB-INF/security.xml]] *

![.jar needed][1]

你能为我的问题提出建议吗? thx agung

1 个答案:

答案 0 :(得分:1)

我不使用Netbeans,所以我不知道它的来龙去脉,但是这个错误信息似乎表明事先已经发生了一些错误/异常。构建日志中真的没有更多内容吗?

无论如何,不​​确定这是否解决了问题并且与具体问题有关,但有一点引起我注意的是,当你使用JSF 2时,你的<facelet-taglib>被声明符合Facelets 1.x。 x捆绑了Facelets 2.x. Netbeans可能已经超过了那个。

修复.taglib.xml文件的根声明,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0"
>
    <!-- Config here. -->
</facelet-taglib>

此外,Glassfish是一个Servlet 3.0兼容容器,但您的web.xml根声明符合Servlet 2.5。从技术上讲,这应该不会立即引起问题,但是你会以这种方式错过Servlet 3.0 / EL 2.2的优势。

我也修复了web.xml的根声明:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    version="3.0"
>
    <!-- Config here. -->
</web-app>

更新根据您的更新,您的具体问题的根本原因如下:

  

java.lang.NoClassDefFoundError:org / springframework / webflow / execution / RequestContext

NoClassDefFoundError表示类路径中缺少消息中提到的类,而应用程序中的其他类(间接)需要它。解决方案是将类(或在此特定情况下,带有类的JAR文件)添加到类路径中。提到的类是Spring WebFlow的一部分。您需要下载它并将其包含在类路径(IDE调用它的构建路径)中,就像您对核心Spring框架和Spring Security一样。


根据您的第二次更新,

更新2 ,修复第一次更新后出现了新问题:

  

无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/security]攻击资源:ServletContext资源[/WEB-INF/security.xml]

我不是春天的人,所以我无法从头顶回答,但是Google表明这个问题是由于缺少Spring Security Config JAR文件引起的。