복붙노트

[SPRING] 스프링 부트 및 JSF / Primefaces / Richfaces

SPRING

스프링 부트 및 JSF / Primefaces / Richfaces

나는 지금 몇 달 동안 Spring과 연락을 취해 왔고 최근에는 Guide 섹션을 탐색하면서 Spring Boot를 만나게되었습니다. 이 가이드는 프로젝트의 기본 (그리고 멋진) 아이디어를 아주 쉽게 이해할 수 있도록 만들어졌으며, 최소한의 구성으로 엔터프라이즈 급 애플리케이션을 구축 및 배포하면서 다양한 Spring / JEE 's 좋은 습관. 저는 테스트 프로젝트를 위해 Spring Boot를 사용하는데 정말로 관심이 있습니다. 그 이유는 설정과 실행이 훨씬 쉽고 빠르며 여전히 프로덕션 환경에 아주 가까이 있기 때문입니다. 저는 현재 Spring Boot와 Primeface를 사용하여 프로젝트를 선택하려고합니다.하지만이 설정은 Thymeleaf의 경우와 마찬가지로 준비가되어 있지 않습니다. 클래스 패스에 바이너리가있는 경우 충분하다. 나는 성공하지 않고 folowing gradle / maven 아티팩트를 포함 해 보았습니다.

스프링 부트의 임베디드 Tomcat 서버는 명백한 오류없이 시작되지만 브라우저에서 / view와 같은 페이지를 열려고 시도하면 임베디드 서버는 다음과 같은 오류 메시지를 표시합니다. HTTP 상태 500 - 순환 뷰 경로 : 현재 처리기로 다시 디스패치합니다. URL을 다시 입력하십시오. ViewResolver 설정을 확인하십시오! (힌트 : 이것은 기본 뷰 이름 생성으로 인해 지정되지 않은 뷰의 결과 일 수 있습니다.)

여러 다른 장소에서 검색 한 후에도 이러한 프로젝트를 설정하는 방법에 대한 자습서는 찾지 못했습니다. 내 build.gradle 파일의 내용은 다음과 같습니다.

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC4")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

idea {
    module {
        downloadJavadoc = true
    }
}

group = 'com.hello'
version = '0.0.1-SNAPSHOT'

repositories {
    mavenCentral()
    mavenLocal()
    maven { url "http://repository.primefaces.org" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
//    compile ("org.thymeleaf:thymeleaf-spring4")
    compile group: 'org.primefaces', name: 'primefaces', version: '4.0'

    compile group: 'com.sun.faces', name: 'jsf-api', version: '2.2.2'
    compile group: 'com.sun.faces', name: 'jsf-impl', version: '2.2.2'
    compile group: 'javax.el', name: 'el-api', version: '1.0'
}

task wrapper(type: Wrapper) {
    gradleVersion=1.10
}

내 주요 수업 :

package com.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@EnableAutoConfiguration
@ComponentScan
@Configuration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

내 WebMvcConfigurerAdapter 구현 :

package com.hello;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("view");
        registry.addViewController("/view").setViewName("view");
    }

}

내 view.html 파일 (view.xhtml도 시도 함)과 함께 최소한의 설치를 위해이 프로젝트를 위해 만든 모든 파일입니다.

누구든지 내가 뭘 잘못하고 있는지 (또는 전혀하지 않고) 볼 수 있다면 도움을 많이 주시면 감사하겠습니다. 이 경우 JSF 구성을 위해 추가 파일 / 빈이 필요합니까? 그렇다면 어디서 어떻게 그러한 파일을 넣어야합니까?

이 질문은 공식 스프링 포럼에도 게시되었습니다 : http://forum.spring.io/forum/spring-projects/boot/746552-spring-boot-and-jsf-primefaces-richfaces

편집하다: JSF 용 M. Deinum 구성 빈을 포함하고 Spring MVC와 관련된 WebMvcConfigurerAdapter 정의를 제거한 후 Spring Boot는 요청을 FacesServlet 인스턴스에 매핑하는 것처럼 보입니다. 이제 다음과 같은 오류 메시지가 나타납니다.     HTTP Status 500 - 서블릿 FacesServlet에 대한 Servlet.init ()가 예외를 던졌습니다.

java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory

새 JsfConfig bean의 코드는 다음과 같습니다.

package com.hello;

import com.sun.faces.config.ConfigureListener;
import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.faces.webapp.FacesServlet;

@Configuration
public class JsfConfig {

    @Bean
    public FacesServlet facesServlet() {
        return new FacesServlet();
    }

    @Bean
    public ServletRegistrationBean facesServletRegistration() {
        ServletRegistrationBean registration = new ServletRegistrationBean(facesServlet(), "*.xhtml");
        registration.setName("FacesServlet");
        return registration;
    }

    @Bean
    public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
        return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
    }

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/templates/");
        resolver.setSuffix(".xhtml");
        return resolver;
    }
}

해결법

  1. ==============================

    1.Spring MVC와 함께 작동하지 않는 JSF를 사용하고 있는데 둘 다 다른 기술입니다. JSF를 올바르게 설정해야합니다. 이를 위해서는 FacesServlet과 Face ConfigureListener를 추가해야합니다. JSF를 올바르게 설정하려면 ConfigureListener가 필요합니다. 일반적으로 ConfigureListener는 자동으로 감지되지만 임베디드 버전은 실제로 그렇게 보이지 않습니다.

    Spring MVC와 함께 작동하지 않는 JSF를 사용하고 있는데 둘 다 다른 기술입니다. JSF를 올바르게 설정해야합니다. 이를 위해서는 FacesServlet과 Face ConfigureListener를 추가해야합니다. JSF를 올바르게 설정하려면 ConfigureListener가 필요합니다. 일반적으로 ConfigureListener는 자동으로 감지되지만 임베디드 버전은 실제로 그렇게 보이지 않습니다.

    @Configuration
    public class JsfConfig {
    
        @Bean
        public FacesServlet facesServlet() {
            return new FacesServlet();
        }
    
        @Bean
        public ServletRegistrationBean facesServletRegistration() {
            ServletRegistrationBean registration = new ServletRegistrationBean(facesServlet(), "*.xhtml");
            registration.setName("FacesServlet")
            return registration;
        }
    
        @Bean
        public ListenerRegistationBean jsfConfigureListener() {
            return new ListenerRegistrationBean(new ConfigureListener());           
        }       
    }
    

    이 같은. DispatcherServlet 등의 자동 설정을 비활성화하는 방법은 JSF를 사용하고 Spring MVC는 사용하지 않는 것이 좋습니다.

    @EnableAutoConfiguration(exclude={WebMvcAutoConfiguration.class,DispatcherServletAutoConfiguration }
    
  2. ==============================

    2.스프링 부트로 FacesServlet을 설정 한 후에 다른 문제에 대해 louvelg에서이 질문을 본 후 Spring Web에서 몇 가지 구성 파일과 ServletRegistrationBean을 추가하여 JSF / primefaces로 작업하게했습니다. web.xml 및 faces-config.xml 파일은 xml 파일이 많지 않은 Spring Boot의 생각을 최소한으로 해줍니다.하지만 이것은 JSF에서 발견 할 수있는 최소한의 설정입니다. 이 일을하는 길은 제게 알려주세요.

    스프링 부트로 FacesServlet을 설정 한 후에 다른 문제에 대해 louvelg에서이 질문을 본 후 Spring Web에서 몇 가지 구성 파일과 ServletRegistrationBean을 추가하여 JSF / primefaces로 작업하게했습니다. web.xml 및 faces-config.xml 파일은 xml 파일이 많지 않은 Spring Boot의 생각을 최소한으로 해줍니다.하지만 이것은 JSF에서 발견 할 수있는 최소한의 설정입니다. 이 일을하는 길은 제게 알려주세요.

    내 gradle.build 파일의 종속성은 다음과 같습니다.

    compile group: "org.springframework.boot", name: "spring-boot-starter"
    compile group: "org.springframework", name: "spring-web", version: "4.0.2.RELEASE"
    
    compile group: "org.apache.tomcat.embed", name: "tomcat-embed-core", version: tomcatVersion
    compile group: "org.apache.tomcat.embed", name: "tomcat-embed-logging-juli", version: tomcatVersion
    compile group: "org.apache.tomcat.embed", name: "tomcat-embed-jasper", version: tomcatVersion
    
    compile group: "org.primefaces", name: "primefaces", version: "4.0"
    compile group: "com.sun.faces", name: "jsf-api", version: "2.1.21"
    compile group: "com.sun.faces", name: "jsf-impl", version: "2.1.21"
    

    여기서 tomcat 버전은 "7.0.34"입니다. 여기서 중요한 변경 사항은 다음과 같습니다.

    내 메인 클래스의 새로운 내용은 다음과 같습니다.

    package com.hello;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.context.embedded.ServletRegistrationBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    
    import javax.faces.webapp.FacesServlet;
    
    @Configuration
    @ComponentScan
    @EnableAutoConfiguration
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        @Bean
        public ServletRegistrationBean servletRegistrationBean() {
            FacesServlet servlet = new FacesServlet();
            return new ServletRegistrationBean(servlet, "*.xhtml");
        }
    }
    

    @EnableAutoConfiguration : Spring Boot가 Tomcat을 자동으로 설정하고 ServletRegistrationBean이 xhtml 요청을 FacesServlet에 매핑하도록하려면.

    webapp 디렉토리의 WEB-INF / faces-config.xml 파일 :

    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
                  version="2.2">
        <application>
            <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        </application>
    </faces-config>
    

    또한 webapp / WEB-INF의 web.xml 파일 :

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               version="2.5">
    
        <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>*.xhtml</url-pattern>
        </servlet-mapping>
    </web-app>
    

    서블릿 정의는 중복 된 것처럼 보이지만 web.xml 파일이나 서블릿 등록 빈에서 제거하면 어떤 이유로 xhtml 페이지 렌더링이 예상대로 또는 전혀 작동하지 않습니다. 편집 : 서블릿 매핑 web.xml 파일에서 필요하지 않습니다 밝혀졌습니다, 그것은 IDE 문제, 내 경우에는 Intellij 아이디어 서블릿 등록 빈에 정의 된 서블릿 매핑에 대해, 그래서 불평했다 알고하지 않습니다 예상 서블릿에 대한 매핑이 누락되었다고해도 애플리케이션은 아무런 문제없이 실행됩니다.

    기여한 모든 사람에게 감사드립니다.

  3. ==============================

    3.나는이 게시물을 따라했고 나는 같은 오류를 받고 있었다. 이것은 약간의 해킹이지만 현재 내가 얻을 수있는 최선입니다.

    나는이 게시물을 따라했고 나는 같은 오류를 받고 있었다. 이것은 약간의 해킹이지만 현재 내가 얻을 수있는 최선입니다.

    이것을 web.xml 파일의 src / main / webapp / WEB-INF 폴더에 추가하십시오

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://java.sun.com/xml/ns/javaee"       xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            id="WebApp_ID" version="3.0">
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        </servlet>
    </web-app>
    

    이렇게하면 백업 팩토리 문제를 찾을 수 없습니다.

    이 오류가 발생한 후 추가 문제가 발생했습니다.

    It appears the JSP version of the container is older than 2.1 and unable to locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl.  If not using JSP or the EL RI, make sure the context initialization parameter, com.sun.faces.expressionFactory, is properly set.
    

    그래서 나는이 의존성을 추가했다.

    compile "org.glassfish.web:el-impl:2.2"
    

    그리고 이것은 일이 나를 위해 일하기 시작했을 때입니다.

    나는 여전히 web.xml이 필요 없도록 만들고있다. 스프링 부트가 어떻게 작동하는지에 대한 해킹 일종이기 때문에. 이 모든 추가 진행 상황에 대해이 답변에 다시 게시하는 것을 기억하려고 노력하지만, 내가 작성하지 않은 경우 내가 만든이 예제 앱에 추가 할 것입니다.

    https://github.com/Zergleb/Spring-Boot-JSF-Example

  4. ==============================

    4.나는 또한이 같은 문제에 부딪 혔다. [@EnableAutoConfiguration] 없이는 약간 다른 해결책을 발견했습니다.

    나는 또한이 같은 문제에 부딪 혔다. [@EnableAutoConfiguration] 없이는 약간 다른 해결책을 발견했습니다.

    yupom.hmsls

        <?xml version="1.0" encoding="UTF-8"?>
    <project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        ...
        <!-- http://stackoverflow.com/questions/25479986/spring-boot-with-jsf-could-not-find-backup-for-factory-javax-faces-context-face/25509937#25509937 -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.2.4.RELEASE</version>
        </parent>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <!-- JSF -->
            <dependency>
                <groupId>org.glassfish</groupId>
                <artifactId>javax.faces</artifactId>
                <version>2.2.11</version>
            </dependency>
            <!-- JSR-330 -->
            <dependency>
                <groupId>javax.inject</groupId>
                <artifactId>javax.inject</artifactId>
                <version>1</version>
            </dependency>
            <!-- JSP API -->
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
            </dependency>
            <!-- Spring web -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </dependency>
            ...
        </dependencies>
        <build>
            <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
        </build>    
    </project>
    

    및 Java 구성 클래스 :

    ...
    
    @Configuration
     public class JsfConfig extends SpringBootServletInitializer {
    
        @Bean
        public ServletRegistrationBean servletRegistrationBean() {
            FacesServlet servlet = new FacesServlet();
            ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "*.xhtml");
            return servletRegistrationBean;
        }
    
        @Bean
        public EmbeddedServletContainerFactory servletContainer() {
            TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
            factory.setPort(8080);
            factory.setSessionTimeout(10, TimeUnit.MINUTES);
            return factory;
        }
    
    }
    

    [WEB-INF / web.xml에]

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">
    
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        </servlet>
    
    </web-app>
    

    [faces-config.xml]

    <?xml version='1.0' encoding='UTF-8'?>
    <faces-config version="2.2"
                  xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
      <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
      </application>
    </faces-config>
    
  5. ==============================

    5.코드의이 줄은 / view에 대한 요청을 받으면 논리적 이름보기가있는보기로 리디렉션되는 컨트롤러를 등록합니다.

    코드의이 줄은 / view에 대한 요청을 받으면 논리적 이름보기가있는보기로 리디렉션되는 컨트롤러를 등록합니다.

    registry.addViewController("/view").setViewName("view");
    

    뷰 해석기는 논리적 이름을 취하고 접두어와 접미사를 적용하고 view.xhtml과 같은 뷰 정의를 찾습니다.

    여기서 문제는 접미사 또는 접두사를 추가하지 않는 기본보기 확인자가 추가되고있는 것 같습니다.

    기본 뷰 확인자가 정의 된 코드는 WebMvcAutoConfiguration.defaultViewResolver ()를 참조하십시오.

    기본 뷰 해석기는 / view라는 뷰를로드하려고 시도합니다.이 뷰는 동일한 컨트롤러를 다시 트리거하여 루프를 만듭니다.

    addViewController 행에 주석을 달거나 자신 만의 뷰 해석기를 정의하십시오 (예 : 다음과 같이).

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".xhtml");
        return resolver;
    }
    
  6. from https://stackoverflow.com/questions/22544214/spring-boot-and-jsf-primefaces-richfaces by cc-by-sa and MIT license