风人园

弱水三千,只取一瓢,便能解渴;佛法无边,奉行一法,便能得益。
随笔 - 99, 文章 - 181, 评论 - 56, 引用 - 0
数据加载中……

JSF--整合spring

使用JSF-Spring整合
一、下载
进官方网站http://jsf-spring.sourceforge.net,下载lib

二、参考quickstart配置相应文件
http://jsf-spring.sourceforge.net/quickstart.shtml
最终配置结果如下
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
<context-param>
        
<param-name>javax.faces.CONFIG_FILES</param-name>
        
<param-value>
            /WEB-INF/classes/faces/faces-config.xml, 
            /WEB-INF/classes/faces/faces-config-beans.xml
        
</param-value>
    
</context-param>
    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>
            classpath*:spring/applicationContext-*.xml
        
</param-value>
    
</context-param>

    
<servlet>
        
<servlet-name>Faces Servlet</servlet-name>
        
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        
<load-on-startup>0</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>Faces Servlet</servlet-name>
        
<url-pattern>*.faces</url-pattern>
    
</servlet-mapping>
    
<listener>
        
<listener-class>
            org.springframework.web.context.request.RequestContextListener
        
</listener-class>
    
</listener>
    
<listener>
        
<listener-class>
            org.springframework.web.context.ContextLoaderListener
        
</listener-class>
    
</listener>
    
<listener>
        
<listener-class>de.mindmatters.faces.spring.context.ContextLoaderListener</listener-class>
    
</listener>
        
</web-app>

请注意以上listener的顺序,如果位置不同可能出现找不到在spring中定义的bean。请按以上顺序配置即可。

根据quitstart配置完之后可能还有如下异常:
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: de.mindmatters.faces.spring.factory.BeansEvaluationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiBean': Scope 'request' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
de.mindmatters.faces.lifecycle.RenderResponsePhase.executePhase(RenderResponsePhase.java:45)
de.mindmatters.faces.lifecycle.AbstractPhase.execute(AbstractPhase.java:37)
de.mindmatters.faces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:166)
de.mindmatters.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:226)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
然后再把这个listener加上
<listener>
  <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener>

就ok了。

可选
如果还有问题,在faces-config.xml中添加
<application>
     <variable-resolver>
      org.springframework.web.jsf.DelegatingVariableResolver
     </variable-resolver>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
 </application>

posted on 2007-04-26 16:18 风人园 阅读(6082) 评论(3)  编辑  收藏 所属分类: JSF

评论

# re: JSF--整合spring  回复  更多评论   

我按照你的配置修改后,后台老提示
严重: Error configuring application listener of class com.sun.faces.config.ConfigureListener
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1352)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3677)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:608)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1112)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

请问什么原因?我该如何解决? 急啊!
老大
2007-07-16 12:04 | zzb

# re: JSF--整合spring  回复  更多评论   

我的也是这个问题
严重: Error configuring application listener of class com.sun.faces.config.ConfigureListener
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
2007-09-27 17:02 | wxyhibernate

# re: JSF--整合spring  回复  更多评论   

com.sun.faces.config.ConfigureListener在jsf的sun参考实现jsf-impl.jar中。
如果你使用的是apache的myfaces实现的话可以去掉这个listener。
2007-12-04 15:18 | KimmKing

只有注册用户登录后才能发表评论。


网站导航: