首页 > 解决方案 > 将 Primefaces 与 Springboot/JoinFaces 集成时出错

问题描述

我正在尝试按照以下教程创建一个将primefaces与spring boot集成的应用程序:

https://medium.com/@tsepomaleka/integrating-spring-boot-with-java-server-faces-using-joinfaces-297e64f6a28f

https://codenotfound.com/jsf-primefaces-example.html

我按照教程的建议添加了连接面:

这是我的 pom.xml

  <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.M3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.dataprev.election</groupId>
    <artifactId>election</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>election</name>
    <description>Demo System Election</description>

    <properties>
        <java.version>13</java.version>
        <joinfaces.version>4.1.5</joinfaces.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>jsf-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.joinfaces</groupId>
                <artifactId>joinfaces-dependencies</artifactId>
                <version>${joinfaces.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project>

我创建了 webapp/WEB-INF 文件夹结构:

在此处输入图像描述

正如您在图像上看到的那样,webapp 文件夹看起来不像 intellij 识别的那样。

其他问题是您在图像上看到的 xmlns:p="http://primefaces.org/ui" url taglib 未被识别。

所以当我在浏览器上运行时:http://localhost:8080/eleicao.xhtml 浏览器返回错误:

出现意外错误(类型=未找到,状态=404)。/eleicao.xhtml 在 ExternalContext 中未找到作为资源

那么我该如何解决呢?这样我就可以运行 primefaces 页面。

标签: spring-bootintellij-ideaprimefacesjoinfaces

解决方案


您在这里缺少一堆依赖项,这是我的 PrimeFaces 的 pom、JSF 的 MyFaces、OmniFaces 和作为 servlet 引擎的 Undertow

        <!-- JoinFaces -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>primefaces-spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.joinfaces</groupId>
                    <artifactId>tomcat-spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.joinfaces</groupId>
                    <artifactId>mojarra-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>omnifaces3-spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.joinfaces</groupId>
                    <artifactId>tomcat-spring-boot-starter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.joinfaces</groupId>
                    <artifactId>mojarra-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>undertow-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>myfaces-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>rewrite-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>weld-spring-boot-starter</artifactId>
        </dependency>

推荐阅读