Primefaces 与 Springboot/JoinFaces 集成时出错

问题描述 投票:0回答:2

我正在尝试按照以下教程创建一个将 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)。 在ExternalContext 中未找到/eleicao.xhtml 作为资源

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

spring-boot intellij-idea primefaces joinfaces
2个回答
2
投票

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

        <!-- 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>

0
投票

一段时间后,我尝试做与你相同的事情,并在 IntelliJ Idea 上遇到相同的错误。

在我的例子中,我发现一些外部jar(通过maven包含)丢失了,但即使它们在那里,它们也无法正常工作。

在 IntelliJ 中,我什至尝试删除 .m2 chache 并从零开始下载所有内容,通过文件 > 无效缓存忽略所有 chache,但不幸的是效果不佳。

我尝试手动包含丢失的 .jar,但没有任何效果

在阅读了大量内容并尝试了一堆解决方案后,我尝试在 Eclipse 中打开该项目,因为没有任何意义。

令我惊讶的是……一切都很好。我相信在考虑这个解决方案时,这应该是 IntelliJ 上的一个错误。

这是我的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.7.14</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>br.com.leonardomeurer</groupId>
    <artifactId>milhas</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Projeto Controle Milhas</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <joinfaces.version>4.7.14</joinfaces.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>primefaces-spring-boot-starter</artifactId>
        </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>

</project>

© www.soinside.com 2019 - 2024. All rights reserved.