1

質問があります。些細なアプリケーションがあります。Spring MVCを使用したいのですが、JSPページでいくつかのフェイスレットを使用します(私がうまくいっていれば)。しかし、私はそれをすることができません。Geronimoを使用しています。Geronimoには、MyFacesJSFの実装があります。私は今、適切に書くにはどうすればいいfaces-config.xmlのか、何が欠けているのかはわかりません。ブラウザでページを開くと、Geronimoは次のようにスローしIllegalStateEcxeptionます:このアプリケーション用に設定されたファクトリはありません。これは、faces-initializationがまったく機能しない場合に発生します。

アプリケーションでコントローラーを作成しました。

@Controller
public class BasicController {
    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("main");
        return mv;
    }

    @ModelAttribute("appVersion")
    public String getVersion() {
        return Version.VERSION + " (" + Version.BUILD_TIME + ")";
    }
}

web.xmlでディスパッチャーサーブレットを宣言し、サーブレットに直面しています。

<servlet>
    <servlet-name>sd</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>sd</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-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>*.jsp</url-pattern>
</servlet-mapping>
<listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

WEB-INF/sd-servlet.xmlでディスパッチャーサーブレットを構成しました。

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>
<context:component-scan base-package="eu.barbucha.trackAnniversaries.webLayer"/>
<mvc:annotation-driven/>
<mvc:resources location="/files/" mapping="/files/**"/>

faces-config.xmlにはただ1つの宣言が含まれています:

<faces-config>
    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>
</faces-config>

そして最後に、JSPページを作成しました。

<?xml version='1.0' encoding='utf-8'?>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="files/basic.css" media="all"/>
</head>
<body>
    <p>Example <h:outputText value="text"/>.</p>
    <hr/>
    <i>${appVersion}</i>
</body>
</html>
4

1 に答える 1

0

はい、彼らは本当にできます。しかし、上記の構成にはいくつかの間違いがあります。

  1. ファイルはですWEB-INF/pages/main.jspが、JSFサーブレットをマップする必要が*.jsfあり、ビューリゾルバーのサフィックスは同じである必要があります.jsf。MyFacesはサフィックスを自動的に変更します。
  2. その後、それはまだ動作しません。IllegalStateExceptionアプリケーションコンテキストがないことがわかります。Springの適切な構成は、2つのファイルで構成されています。1つ目は、アプリケーションコンテキストであり、2つ目はディスパッチャサーブレットの構成ファイルです。空のアプリケーションコンテキストファイルを作成するだけでは、Geronimoコンテナ全体がフリーズする可能性があります。

構成は2つのファイルに書き込む必要があります。それらの両方をディレクトリに入れますWEB-INF。最初はapplicationContext.xml

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <context:annotation-config />
    <context:component-scan base-package="eu.barbucha.trackAnniversaries.webLayer"/>
</beans>

2つ目は、サーブレットの構成ですsd。これもsd-servlet.xml

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- The name I've choosen SD = Spring Dispatcher (Servlet) -->
    <context:component-scan base-package="eu.barbucha.trackAnniversaries.webLayer"/>
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsf" />
    </bean>
    <mvc:annotation-driven/>
    <mvc:resources location="/files/" mapping="/files/**"/>
</beans>

使用されるソリューション(JSPを使用)はJSF1.2と互換性があります。JSPの代わりにfaceletを使用する場合は、MyFaces2.0などのJSF2.0互換の実装を使用する必要があります。

于 2011-08-09T12:27:12.537 に答える