I was in contact with Spring for only a few months and recently came to Spring Boot while looking at the manual section. The guides were very simple to complete and were made for an initial understanding of the basic (and amazing) design idea, which was to be able to create and deploy enterprise-level applications with minimal configuration, supporting a wide range of Spring / JEE. I am really interested in using Spring Boot for test projects, because with them they are much easier and faster to set up and run and are still very close to my production environment. I am currently trying to create a project using Spring Boot and Primefaces as my chosen technology of choice, but this installation is apparently not ready out of the box, as is the case with Thymeleaf, for which it has its own binary code in the classpath enough . I tried to include the following gradle / maven artifacts, without success:
- primefaces
- Jsf-api
- JSF-real
- el api
Spring A loaded Tomcat server starts without visible errors, but after trying to open a page, such as / view, in a browser, the embedded server displays the following error message: HTTP Status 500 - Circular view path: would dispatch back to the current handler URL again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) HTTP Status 500 - Circular view path: would dispatch back to the current handler URL again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
After searching in several different places, I still cannot find any resources / tutorials on how to set up such a project. Here is the contents of my 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 my 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 with my view.html file (I also tried view.xhtml), these are all the files I created for this project, as I am trying to do a minimal setup.
If someone can understand what I'm doing wrong (or not at all), help will be greatly appreciated. Are additional files / beans needed for JSF configuration in this case? If so, where and how should such files be placed?
This question has also been posted in the official Spring forums: http://forum.spring.io/forum/spring-projects/boot/746552-spring-boot-and-jsf-primefaces-richfaces
EDIT: After enabling the M. Deinum bean configuration for JSF and removing the WebMvcConfigurerAdapter definition (associated with Spring MVC), Spring Boot seems to match requests to the FacesServlet instance, now I get the following error message: HTTP Status 500 - Servlet.init() for servlet FacesServlet threw exception
the main reason:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory
Code for the 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; } }