我正在JSF 1.2项目中实现spring安全性。这在JBoss 5.0.1中成功部署,但当我尝试访问应用程序的登录页面时,它给了我以下异常
Caused by: java.lang.IllegalArgumentException: FacesContext must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.jsf.FacesContextUtils.getWebApplicationContext(FacesContextUtils.java:50)
at org.springframework.web.jsf.FacesContextUtils.getRequiredWebApplicationContext(FacesContextUtils.java:81)
at org.springframework.web.jsf.el.SpringBeanFacesELResolver.getWebApplicationContext(SpringBeanFacesELResolver.java:91)
at org.springframework.web.jsf.el.SpringBeanFacesELResolver.getBeanFactory(SpringBeanFacesELResolver.java:79)
at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:50)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
从这个跟踪中,我猜测springbean是如何在初始化之前使用faces上下文的。
以下是我的项目结构:
MyEar
|-- lib (contains all spring security jar files)
|
|
|-- myWar
|-- META-INF/MANIFEST.MF (entries for spring security jars)
|
|-- WEB-INF
|-- applicationContext.xml
|-- lib (local jar files jsf,facelets etc)
这里有一件事很重要,那就是我希望我所有的spring securities jar都在ear的lib目录中,当我把所有的spring security jar都直接放在ear(earcontent)下而不是在lib中时,这个异常就不会发生。
请告诉我这是否是我的项目结构的问题?
更新:这是我的清单内容:
Manifest-Version: 1.0
Class-Path: lib/aopalliance-1.0.jar
lib/mysql-connector-java-5.1.7-bin.jar
lib/org.springframework.aop-3.0.5.RELEASE.jar
lib/org.springframework.asm-3.0.5.RELEASE.jar
lib/org.springframework.beans-3.0.5.RELEASE.jar
lib/org.springframework.context-3.0.5.RELEASE.jar
lib/org.springframework.core-3.0.5.RELEASE.jar
lib/org.springframework.expression-3.0.5.RELEASE.jar
lib/org.springframework.transaction-3.0.5.RELEASE.jar
lib/org.springframework.web-3.0.5.RELEASE.jar
lib/spring-security-config-3.0.5.RELEASE.jar
lib/spring-security-core-3.0.5.RELEASE.jar
lib/spring-security-taglibs-3.0.5.RELEASE.jar
lib/spring-security-web-3.0.5.RELEASE.jar
以下是web.xml条目的一些部分:
<!-- Delegating to a Spring-managed bean that implements the Filter interface -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBean</param-name>
<param-value>filterChainProxy</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
FacesContext
由FacesServlet
创建。因此,当它是null
时,就意味着您没有调用FacesServlet
。您需要确保浏览器请求URL与您在web.xml
中定义的FacesServlet
的<url-pattern>
相匹配。
如果是
<url-pattern>*.jsf</url-pattern>
然后,您需要确保将登录页面调用为
http://localhost:8080/myWar/login.jsf
因此不是作为
http://localhost:8080/myWar/login.xhtml