2011-08-08 4 views
1

질문이 있습니다. 사소한 응용 프로그램이 있습니다. Spring MVC를 사용하고 JSP 페이지에서 일부 facelets을 사용한다. 그러나 나는 그것을 할 수 없다. 제로니모를 사용하고 있습니다. Geronimo에는 MyFaces JSF 구현이있다. 나는 지금 적절한 방법을 쓰지 않을 것이다. faces-config.xml, 또는 무엇이 빠졌는가? 브라우저에서 페이지를 열면 Geronimo는 IllegalStateEcxeption : No Application을이 어플리케이션에 대해 구성합니다. 이것은 faces-initialization이 전혀 작동하지 않는 경우에 발생합니다.스프링 MVC와 MyFaces를 함께 사용할 수 있습니까?

내가 응용 프로그램에서 CONTROLER을 만든

: 나는 디스패처 서블릿을 선언하고있는 web.xml 서블릿에 직면 한

@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 + ")"; 
    } 
} 

는 :

<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/**"/> 

내그들은 정말 수,

<?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> 

답변

0

예 : (10)는 한 daclaration 포함

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

을 마지막으로 나는 JSP 페이지를 작성했습니다. 그러나 위에서 언급 한 구성에는 몇 가지 실수가 있습니다.

  1. 파일은 WEB-INF/pages/main.jsp하지만 JSF 서블릿은 *.jsf에 매핑해야하고 뷰 리졸버에 접미사가 동일해야합니다 : .jsf합니다. MyFaces는 자동으로 접미사를 변경합니다.
  2. 그렇다면 아직 작동하지 않습니다. IllegalStateException을 얻으면 응용 프로그램 컨텍스트가없는 것입니다. Spring의 적절한 설정은 두 개의 파일로 구성됩니다. 첫 번째는 Dispatcher 서블릿에 대한 두 번째 구성 파일과 응용 프로그램 컨텍스트입니다. 비어있는 응용 프로그램 컨텍스트 파일을 작성하면 Geronimo 컨테이너 전체가 멈출 수 있습니다.

구성을 두 개의 파일로 작성해야합니다. 둘 다 WEB-INF 디렉토리에 넣습니다.

<?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> 

그리고 두 번째는 sd-servlet.xmlsd라는 서블릿에 대한 구성된다 : 먼저 applicationContext.xml입니다 (JSP와)

<?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> 

중고 솔루션 JSF 1.2 호환됩니다. JSP 대신 facelet을 사용하려면 JSF 2.0 호환 구현을 사용해야합니다. MyFaces 2.0.