2

我真的无法解决这个问题。首先,我从 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。

4

1 回答 1

2

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

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

于 2012-08-09T04:42:21.573 回答