我的IntelliJ IDE的專案faces-config.xml檔案中出現此錯誤:
必須宣告元素 faces-config
這是我的 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
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
version="2.3">
</faces-config>
和 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>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
嘗試在您最喜歡的網路瀏覽器中打開http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd 。它回傳 404。換句話說,此 URL 不正確。IDE 的內置 XML 決議器也在以這種方式苦苦掙扎。它在那里找不到<faces-config>根元素的宣告。
目前尚不清楚您打算使用哪個 JSF 版本進行開發。如果它是 2.3,如 所示version="2.3",那么您應該改用http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd,如網頁的“Java EE 8 Schema Resources”部分中所述在http://xmlns.jcp.org/xml/ns/javaee后面。
<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
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
但是如果它確實是 3.0,第一個 Jakartified 版本(即,您應該jakarta.*在所有地方使用 Jakarta EE API 的包而不是javax.*包),那么您應該使用以下部署描述符根宣告,如“Jakarta EE 9”部分中指定的那樣https://jakarta.ee/xml/ns/jakartaee后面的網頁。
<faces-config
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
version="3.0">
也可以看看:
- Jakarta Faces 4.0 規范 - 11.3.5 應用程式配置資源格式
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/484032.html
