这是几年前这个经典主题的 jakarta 9 和 jsf 3 版本: 如何创建模块化 JSF 2.0 应用程序?
上下文是我正在将 Web 应用程序迁移到 tomcat 10.0.x、jakarta 9、jsf3、spring 6 等,如此处已详细介绍的:
创建名为“entityManagerFactory”的 bean 时出错,工厂方法“entityManagerFactory”抛出带有消息的异常
移植(除了一些小故障)看起来几乎没问题,但是似乎仍然存在一个大问题:不再加载来自外部 jar 的 xhtml 页面。
这些罐子具有以下结构:
META-INF\resources\-here xhtml pages-
META-INF\faces-config.xml
META-INF\MANIFEST.MF
META-INF\web-fragment.xml
在旧的工作 javax Web 应用程序中,这些文件如下所示:
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_2_2.xsd"
version="2.2">
</faces-config>
web-fragment.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<name>name_of_the_resources_set</name>
</web-fragment>
在新的非工作 jakarta 9 版本中,它们看起来像这样:
faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
</faces-config>
web-fragment.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment
id="WebFragment_ID"
version="5.0"
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-fragment_5_0.xsd">
<name>name_of_the_resources_set</name>
</web-fragment>
(请注意,我没有像 BalusC 建议中那样定义任何资源解析器: 注意:从 Servlet 3.0 和更新的 JBoss/JSF 2.0 版本开始,如果将文件保存在 /META-INF/resources 文件夹中,则不需要整个 ResourceResolver 方法。上述 ResourceResolver 仅在 Servlet 2.5 或更早的 JBoss/JSF 版本中是必需的,因为它们在 META-INF 资源解析中存在错误。)
我有一个带注释的 @EnableWebMvc 配置类,它扩展了 org.springframework.web.servlet.config.annotation.WebMvcConfigurer,在方法中:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
我也尝试改变模式:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/*/*").addResourceLocations("/resources/");
}
因为我注意到似乎在 spring 6 中 ant 匹配器已经改变,但是从 jar 中加载 xhtml 页面没有任何改变,我不确定是否涉及这个设置。
对于此模式中的内含物:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pa="http://primefaces.org/verona"
xmlns:baseUtil="http://java.sun.com/jsf/composite/common/base/util">
...
<baseUtil:outputTextTruncate msgToTruncate="#{myBean.myValue}" maxLength="12"/>
我收到这样的错误:
jakarta.servlet.ServletException: <baseUtil:outputTextTruncate> Tag Library supports namespace: http://java.sun.com/jsf/composite/common/base/util, but no tag was defined for name: outputTextTruncate
对于这样的内含物:
<ui:include src="/common/base/pages/prospetto.xhtml" />
错误是这样的:
jakarta.servlet.ServletException: <ui:include src="/common/base/pages/prospetto.xhtml"> Invalid path : /common/base/pages/prospetto.xhtml
如果为了测试,我尝试渲染一个 jsf 页面,从 jar 中删除 xhtml 部分的内容,则页面将被渲染。
在 web 应用程序的雅加达之前的旧版本中,一切正常(tomcat8-jdk8,spring 5 / tomcat 9 jdk17 spring 5。)
有任何建议和想法欢迎提出,谢谢!