6

我正在运行以下问题。

目前,我有一些托管 Bean 在两个 JSF 应用程序之间共享。由于我不想在两者中复制和粘贴代码(将来会更多),我已将此共享托管 bean 放入 JAR 库中。我关注了这个博客:http: //jsflive.wordpress.com/2011/03/24/custom-component-library/

好吧,即使我将 faces-config.xml 放在 JAR/META-INF/ 中,@ManagedBean 和 @ViewScoped 也不起作用。我不知道为什么,但是如果我在 faces-config.xml 中注册 bean(JAR 的,而不是 WAR 的)这个问题就消失了。

我可以忍受这个,但令我惊讶的是,在 JAR 库中没有为这个托管 bean 调用 @PostConstruct 注释。我没有收到任何错误、警告或其他信息。我想 bean 正在加载,但它们的注释没有被处理。

有没有人遇到过这个?

我的环境:Glassfish 3.1.1 (build 12) JSF 2.1.3

提前致谢。

4

2 回答 2

15
于 2011-08-29T18:40:11.040 回答
8

Also note that post-construct method must not be declared to throw any checked exception. Message from stderr:

Method 'public void my.app.MyBean.postConstruct() throws java.lang.Exception' marked with the 'javax.annotation.PostConstruct' annotation cannot declare any checked exceptions. This method will be ignored.
于 2013-02-13T11:23:46.223 回答