Spring Boot and JSF/Primefaces/Richfaces -
i have been in contact spring few months , came upon spring boot while browsing guides section. guides easy complete , made initial grasp of projects's basic (and awesome) idea, able build , deploy enterprise-level applications minimal configuration while upholding wide array of spring's/jee's practices. interested in using spring boot test projects since easier , faster set , run , still close production environment. trying build project spring boot , primefaces view technology of choice, setup apparently isn't ready out-of-the-box case thymeleaf, having binary in classpath enough. tried including folowing gradle/maven artifacts, no success:
- primefaces
- jsf-api
- jsf-impl
- el-api
spring boot's embedded tomcat server starts no apparent errors, after trying open page such /view in browser, embedded server displays following error message: http status 500 - circular view path: dispatch current handler url again. check viewresolver setup! (hint: may result of unspecified view, due default view name generation.)
after searching in several different places, still fail locate resources/tutorials on how set such project. here contents of build.gradle file:
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 }
my main class:
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); } }
and implementation of 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"); } }
along view.html file (i tried view.xhtml), these files created project i'm trying minimal setup.
if can see i'm doing wrong (or not doing @ all), appreciated. need files/beans jsf configuration in case? if so, , how should put such files?
this question has been posted in official spring forums: http://forum.spring.io/forum/spring-projects/boot/746552-spring-boot-and-jsf-primefaces-richfaces
edit: after including m. deinum's configuration bean jsf , removing webmvcconfigureradapter definition (related spring mvc), spring boot seems map requests facesservlet instance, following error message: http status 500 - servlet.init() servlet facesservlet threw exception
java.lang.illegalstateexception: not find backup factory javax.faces.context.facescontextfactory
the code new 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; } }
you using jsf isn't going work spring mvc both different technologies. have setup jsf correctly. need add facesservlet
, faces configurelistener
.this needed setup jsf correctly, configurelistener
detected automatically embedded versions don't seem that.
@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()); } }
something this. advice disable auto config dispatcherservlet etc. using jsf , not spring mvc.
@enableautoconfiguration(exclude={webmvcautoconfiguration.class,dispatcherservletautoconfiguration }
Comments
Post a Comment