0

我在实现 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]

*解决方案 [违规资源:ServletContext 资源 [/WEB-INF/security.xml]] *

![.jar needed][1]

你能为我的问题提出建议吗?谢谢阿贡

4

1 回答 1

1

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

无论如何,不​​确定这是否解决了问题并且与具体问题有关,但引起我注意的一件事是,<facelet-taglib>当您使用捆绑了 Facelets 2.x 的 JSF 2.x 时,您被声明为符合 Facelets 1.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]

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

于 2012-05-18T11:16:16.747 回答