I have a spring boot primefaces hello world project:
primefaces-demo
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── primefacesdemo
│ │ │ ├── MySpringBootApplication.java
│ │ │ └── HelloWorld.java
│ │ └── resources
│ │ ├── META-INF
│ │ │ └── resources
│ │ └── index.xhtml
├── pom.xml
and here is my bean class:
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
@Named(value = "HelloWorld")
@ViewScoped
public class HelloWorld{
public String message = "Hello, PrimeFaces!";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
and my index.xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Hello World with PrimeFaces</title>
</h:head>
<h:body>
<h:form>
<p:panel header="Hello World">
<h:outputText value="#{HelloWorld.message}" />
</p:panel>
</h:form>
</h:body>
</html>
and my dependencies:
<!-- Spring Boot Starter Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- PrimeFaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>14.0.0</version>
</dependency>
<!-- Jakarta Faces API -->
<dependency>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
<version>4.1.0</version>
</dependency>
<!-- Jakarta Faces Implementation -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>4.1.1</version>
</dependency>
<!-- Jakarta Inject API -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Jakarta CDI API -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>4.1.0</version>
</dependency>
<!-- Spring Boot DevTools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
I’m using java 17 and Spring boot version 3.2.2.
When i launch my app using the maven command: mvn spring-boot:run, and then i access to the : http://localhost:8080/index.xhtml, it shows me a blank page.
I did not configur the web.xml page because spring configure it automatically and for the faces-config.xml, i did not use it because it is a hello world project.
Update:
I added this class:
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import jakarta.annotation.PostConstruct;
import jakarta.faces.webapp.FacesServlet;
@Configuration
public class JsfConfig implements WebMvcConfigurer {
@Bean
public ServletRegistrationBean<FacesServlet> facesServletRegistration() {
ServletRegistrationBean<FacesServlet> registration = new ServletRegistrationBean<>(new FacesServlet(), "*.xhtml");
registration.setLoadOnStartup(1);
return registration;
}
@PostConstruct
public void init() {
// This will set the project stage to Development
System.setProperty("javax.faces.PROJECT_STAGE", "Development");
}
}
and here is my new pom.xml file:
<dependencies>
<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- PrimeFaces and Jakarta EE dependencies -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>14.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<!-- Thymeleaf extras for Jakarta -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-el-api</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
and now, it shows me this error:
java.lang.IllegalStateException: Could not find backup for factory
jakarta.faces.context.FacesContextFactory.
3