【问题标题】:JSF 2 + Spring 3: Cannot get it workJSF 2 + Spring 3:无法正常工作
【发布时间】:2012-08-06 05:50:42
【问题描述】:

我真的无法解决这个问题。 首先,我从 STS 创建了一个 Spring 模板项目(Spring MVC)。

然后我完全复制了http://blog.terrencemiao.com/archives/spring-3-shacks-up-jsf-2-the-maverick-way 报告的代码,但它对我不起作用。

我认为该代码中至少存在一个错误,即“applicationConfigure.xml 应该是 applicationContext.xml”。我更正了它,但它还不起作用。

除了那个网站上报告的文件(相同的结构),我还有:

(1) 根上下文(WEB-INF/spring)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:faces="http://www.springframework.org/schema/faces"
 xmlns:mongo="http://www.springframework.org/schema/data/mongo"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                    http://www.springframework.org/schema/mvc
                    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                    http://www.springframework.org/schema/faces
                    http://www.springframework.org/schema/faces/spring-faces-2.2.xsd
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                ">  
<!-- Root Context: defines shared resources visible to all other web components -->

(2) servlet-context (WEB-INF/spring/appServlet)

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"     
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
xmlns:beans="http://www.springframework.org/schema/beans"     
xmlns:context="http://www.springframework.org/schema/context"     
xsi:schemaLocation="http://www.springframework.org/schema/mvc     
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd     
http://www.springframework.org/schema/beans     
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
http://www.springframework.org/schema/context     
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<context:component-scan base-package="org.paradise.sandbox" />

================================

其余部分完全相同。不幸的是,当我启动服务器并打开 localhost:8080/HelloSpring/helloSpring 时,我收到以下错误:

严重:servlet [DispatcherServlet] 在路径 [/HelloSpring] 的上下文中的 Servlet.service() 引发异常 [圆形视图路径 [helloSpring]:将再次分派回当前处理程序 URL [/HelloSpring/helloSpring]。检查您的 ViewResolver 设置! (提示:由于默认视图名称生成,这可能是未指定视图的结果。)] 根本原因 javax.servlet.ServletException:循环视图路径 [helloSpring]:将再次分派回当前处理程序 URL [/HelloSpring/helloSpring]。检查您的 ViewResolver 设置! (提示:由于默认视图名称生成,这可能是未指定视图的结果。) 在 org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:292) 在 org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:214) 在 org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) 在 org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180) 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950) 在 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 在 org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 在 com.springsource.insight.collection.tcserver.request.HttpRequestOperationCollectionValve.traceNextValve(HttpRequestOperationCollectionValve.java:116) 在 com.springsource.insight.collection.tcserver.request.HttpRequestOperationCollectionValve.invoke(HttpRequestOperationCollectionValve.java:98) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 在 org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 在 java.lang.Thread.run(Thread.java:722)

【问题讨论】:

    标签: spring jsf spring-mvc


    【解决方案1】:

    它不起作用,因为您的 InternalViewResolver 正在“/WEB-INF/views/”下寻找 helloSpring.jsp 文件,而您拥有的文件是 helloSpring.xhtml。

    您可以将后缀更改为值“.xhtml”或使用 .jsp 视图文件。

    【讨论】:

    • 您好,如果有效,您可以将答案标记为正确吗?谢谢
    猜你喜欢
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 2014-03-23
    • 2012-09-26
    • 2012-11-16
    • 2018-10-29
    相关资源
    最近更新 更多