I'm trying to create a JSF project managed by Spring boot 3.0. But it doesn't work no matter how I do it. I can't find any example on the web.
My dependencies:
implementation 'org.springframework.boot:spring-boot-starter-web:3.0.2'
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:10.1.5'
implementation 'org.glassfish:jakarta.faces:4.0.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.0.2'
My MainApplication class:
@SpringBootApplication
public class ManagementClientApplication implements ServletContextAware {
public static void main(String[] args) {
SpringApplication.run(ManagementClientApplication.class, args);
}
@Bean
public ServletRegistrationBean<FacesServlet> servletRegistrationBean() {
ServletRegistrationBean<FacesServlet> servletRegistrationBean = new ServletRegistrationBean<>(new FacesServlet(), "*.xhtml");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
@Override
public void setServletContext(ServletContext servletContext) {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
servletContext.setInitParameter("jakarta.faces.FACELETS_SKIP_COMMENTS", "true");
}
}
My config 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>
A test XHTML file:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
</h:head>
<h:body>
<h:form>
<h:outputText id="greeting" value="Hello world !" />
</h:form>
</h:body>
</html>
Logs :
2023-02-02T17:21:10.844+01:00 INFO 6312 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-02-02T17:21:10.845+01:00 INFO 6312 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 738 ms
2023-02-02T17:21:11.133+01:00 ERROR 6312 --- [ main] jakarta.faces : Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
2023-02-02T17:21:11.149+01:00 ERROR 6312 --- [ main] jakarta.faces : L’application n’a pas été initialisée correctement au démarrage. Impossible de localiser la Fabrique : jakarta.faces.context.FacesContextFactory. Attempting to find backup.
2023-02-02T17:21:11.150+01:00 ERROR 6312 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Servlet.init() for servlet [facesServlet] threw exception
java.lang.IllegalStateException: Could not find backup for factory jakarta.faces.context.FacesContextFactory.
at jakarta.faces.FactoryFinderInstance.notNullFactory(FactoryFinderInstance.java:497) ~[jakarta.faces-4.0.1.jar:4.0.1]
at jakarta.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:190) ~[jakarta.faces-4.0.1.jar:4.0.1]
at jakarta.faces.FactoryFinder.getFactory(FactoryFinder.java:263) ~[jakarta.faces-4.0.1.jar:4.0.1]
at jakarta.faces.webapp.FacesServlet.acquireFacesContextFactory(FacesServlet.java:493) ~[jakarta.faces-4.0.1.jar:4.0.1]
Links I looked at:
How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat? Spring Boot JSF Integration
The project with Spring boot 2 and Javax that I tried to reproduce:
https://github.com/xtremebiker/jsf-spring-boot
I don't understand what I'm doing wrong. I can't find anything on the web. Any help would be welcome.
Thank you all