Maven tomcat:运行目标和基于jsf注释的组件/转换器/验证器扫描

发布于 2024-10-07 14:57:49 字数 1028 浏览 0 评论 0原文

我正在开发 JSF 2.0 应用程序 (Mojarra+Primefaces) 并使用 maven 构建环境。在我使用 faces-config.xml 文件注册自定义转换器和验证器之前,到目前为止一切都很顺利。然后我看到了 JSF 2.0 的一些语法糖——基于注释的配置方法。现在我想使用它,而不是 xml 配置文件。问题是 Mojarra 没有扫描我带注释的类。我发现我需要将 属性设置为 false。现在它可以工作,但前提是我使用 mvn tomcat 启动我的应用程序: run-war 目标,而不是 < code>mvn tomcat:run动态项目,开发起来更舒服。 JSP 2.0 的规范指出:

如果 WEB-INF/faces-config.xml 文件中的元素 包含值为“true”的元数据完整属性,实现不得执行注释 扫描除实现本身提供的类之外的任何类。否则,继续 如下。

如果运行时发现应用程序配置资源中的条目与注释之间存在冲突, 应用程序配置资源中的条目优先。 必须扫描 WEB-INF/classes 中的所有类。

对于应用程序 WEB-INF/lib 目录中的每个 jar,如果该 jar 包含“META-INF/faces-config.xml” 文件或与正则表达式“.*.faces-config.xml”匹配的文件(即使是空文件),所有类 必须扫描该罐子。

但它没有提到在 Maven 构建环境中运行的动态项目:)!有人有解决这个问题的办法吗?

干杯,

凯文

I'm developing a JSF 2.0 application (Mojarra+Primefaces) and using the maven build environment. Before I have used the faces-config.xml file for registering of my custom converters and validators, everything went well so far. Then I saw some syntactic sugar of JSF 2.0 - the annotation based configuration approach. And now I would like to use it, instead of the xml config file. A problem was that Mojarra didn't scan my annotated classes. I figured out that I needed to put the <faces-config ... metadata-complete="false"> attribute to false. Now it works but only if I start my application with mvn tomcat:run-war goal and not with the mvn tomcat:run dynamic project, which is more comfortable for development. The specification of JSP 2.0 says that:

If the element in the WEB-INF/faces-config.xml file
contains metadata-complete attribute whose value is "true", the implementation must not perform annotation
scanning on any classes except for those classes provided by the implementation itself. Otherwise, continue as
follows.

If the runtime discovers a conflict between an entry in the Application Configuration Resources and an annotation, the
entry in the Application Configuration Resources takes precedence.
All classes in WEB-INF/classes must be scanned.

For every jar in the application's WEB-INF/lib directory, if the jar contains a "META-INF/faces-config.xml"
file or a file that matches the regular expression ".*.faces-config.xml" (even an empty one), all classes in
that jar must be scanned.

But it says nothing about dynamic projects running in maven build environment :)! Do anyone has a solution for that problem?

Cheers,

Kevin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

任谁 2024-10-14 14:57:49

我也遇到了这个问题,但发现添加 war:inplace 目标使其对我有用。即使用

mvn clean war:inplace tomcat:run

而不只是“tomcat:run”,它应该可以正常工作。

I also had this problem, but found that adding the war:inplace goal made it work for me. i.e. use

mvn clean war:inplace tomcat:run

instead of just 'tomcat:run' and it should work just fine.

心如狂蝶 2024-10-14 14:57:49

就我而言,log4j-web 中的 Log4jServletContainerInitializer 以某种方式阻止调用 javax.faces 中的 FacesInitializer,它负责处理带注释的 JSF 类。

使用 tomcat8-maven-plugin 和嵌入式 tomcat 8.0.52。

war:inplace 有效,或者只是删除 log4j-web (使用手动 log4j 初始化和上下文管理)。

In my case the Log4jServletContainerInitializer in log4j-web was somehow preventing the FacesInitializer in javax.faces from being called, which is responsible for processing annotated JSF classes.

Using tomcat8-maven-plugin and embedded tomcat 8.0.52.

war:inplace worked, or just removing log4j-web (with manual log4j initialization and context management).

奈何桥上唱咆哮 2024-10-14 14:57:49

添加 org.apache.myfaces.annotation.SCAN_PACKAGES 为我修复了 tomcat7:run 目标

Adding org.apache.myfaces.annotation.SCAN_PACKAGES fixed the tomcat7:run goal for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文