Weblogic 10.3.4 上的 @PostConstruct 注释未被调用

发布于 2024-11-07 07:10:24 字数 2074 浏览 1 评论 0 原文

(这似乎是 https://stackoverflow.com/questions/5862085/weblogic10-3- 的重复项ignores-postconsturt-method,但细节很少,没有得到解答)。

我有一个像这样的 ManagedBean:

public class TestBean {
    private String greeting = "Hello, World!";

    public TestBean() {
    }

    public String getGreeting() {
      System.out.println( "getGreeting called, returning " + this.greeting );
      return greeting;
}

public void setGreeting( String message ) {
      this.greeting = message;
}


    @PostConstruct
    public void prepareSomething() {
        System.out.println( "\n\nPostConstruct called.\n\n" );
        this.greeting += " (PostConstruct was called)";
    }
}

在我的 xhtml 中,我只有 Bean Message: #{TestBean.greeting}。但是,当访问该页面时,不会调用该方法,我得到的不是

Bean Message: Hello, World!

预期的

Bean Message: Hello, World! (PostConstruct was called)

控制台,而是显示来自 getGreeting() 方法的 sysout,而不是来自 prepareSomething()< /code>:

INFO: Added Library from: zip:/data/java/wl1034/user_projects/domains/wlrep1034/autodeploy/PCTest.ear/PCTest.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
getGreeting called, returning Hello, World!
2011-05-12 10:36:11,720 DEBUG org.richfaces.skin.SkinFactoryImpl - Create new Skin instance for name DEFAULT 

更多信息:我正在使用 JSF 1.2(使用 Weblogic 10.3.4 的 MW_HOME/common/deployable-libs/jsf-1.2.war!/WEB-INF/lib 中的 jars), Facelets 1.1.14,RichFaces 3.3.2。我在 WEB-INF/lib 上有以下 jars:

commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar
jsf-facelets.jar
log4j-1.2.16.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
SimpleJSF.jar
wls.jsf.di.jar

我也尝试放置/删除 annotations-api.jar ,症状相同。

如果需要的话我可以发布其他文件。

(This seems a duplicate of https://stackoverflow.com/questions/5862085/weblogic10-3-ignores-postconsturt-method, but that has little details and is not answered).

I have a ManagedBean like this:

public class TestBean {
    private String greeting = "Hello, World!";

    public TestBean() {
    }

    public String getGreeting() {
      System.out.println( "getGreeting called, returning " + this.greeting );
      return greeting;
}

public void setGreeting( String message ) {
      this.greeting = message;
}


    @PostConstruct
    public void prepareSomething() {
        System.out.println( "\n\nPostConstruct called.\n\n" );
        this.greeting += " (PostConstruct was called)";
    }
}

and in my xhtml, I have simply Bean Message: #{TestBean.greeting}. When accessing the page, however, the method is not called, and what I get is

Bean Message: Hello, World!

instead of the expected

Bean Message: Hello, World! (PostConstruct was called)

Console does display sysout's from the getGreeting() method, but not from prepareSomething():

INFO: Added Library from: zip:/data/java/wl1034/user_projects/domains/wlrep1034/autodeploy/PCTest.ear/PCTest.war/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
getGreeting called, returning Hello, World!
2011-05-12 10:36:11,720 DEBUG org.richfaces.skin.SkinFactoryImpl - Create new Skin instance for name DEFAULT 

Further info: I am using JSF 1.2 (using the jars from Weblogic 10.3.4's MW_HOME/common/deployable-libs/jsf-1.2.war!/WEB-INF/lib), Facelets 1.1.14, RichFaces 3.3.2. I have the following jars on WEB-INF/lib:

commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar
jsf-facelets.jar
log4j-1.2.16.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
SimpleJSF.jar
wls.jsf.di.jar

I have tried placing/removing annotations-api.jar as well, same symptoms.

I may post other files if necessary.

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

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

发布评论

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

评论(2

友谊不毕业 2024-11-14 07:10:24

我不使用 Weblogic,但如果我没记错的话,Weblogic 已经附带了它自己的 JSTL/JSF 库。所以您根本不需要自己提供它们。

但如果我错了并且 Weblogic 没有附带它们,那么这些库看起来就不太正确。到底是什么版本?

glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar

@PostConstruct 仅适用于 JSF 1.2 或更高版本。您可以在此处下载 JSF 1.2。它存在两个 JAR 文件

jsf-api.jar
jsf-impl.jar

您只需确保您的 faces-config.xml 声明符合 JSF 1.2 规范,并且 web.xml 声明符合 至少 Servlet 2.5 规范。

最后,JSTL 库应该是这个

I don't use Weblogic, but if I am not wrong, Weblogic already ships with its own JSTL/JSF libraries. So you don't need to supply them yourself at all.

But if I am wrong and Weblogic don't ship with them, then those libraries doesn't look quite right. What versions exactly are those?

glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar

The @PostConstruct works on JSF 1.2 or newer only. You can download JSF 1.2 here. It exist of two JAR files

jsf-api.jar
jsf-impl.jar

You only need to ensure that your faces-config.xml is declared conform JSF 1.2 specification and also that web.xml is declared conform at least Servlet 2.5 specification.

Finally, the JSTL library should be this one.

笑饮青盏花 2024-11-14 07:10:24

再次回答我自己的问题...似乎,虽然您可以将 Weblogic 的 JSF 库嵌入到您自己的应用程序中(这对我们公司来说是可取的,因为我们开发的产品应该对多个客户的安装影响很小),但依赖项注入和发布-构造机制仅在您实际部署库并引用它时才起作用。

这个网站帮助了我:http://blog.eisele .net/2009/02/jsf-versions-and-weblogic-server.html

简而言之,我必须将 Weblogic 的 JSF war 部署为库,从我自己的应用程序中删除它的 jar(也删除annotations-api),并将以下内容添加到我的 WEB-INF/weblogic.xml 中:

<library-ref>
  <library-name>jsf</library-name>
  <specification-version>1.2</specification-version>
  <implementation-version>1.2</implementation-version>
  <exact-match>false</exact-match>
</library-ref>

我还必须重写一些使用 @PostConstruct 不止一次。这适用于 Websphere、Jetty 和 Tomcat,但 Weblogic 明确禁止多次使用它:

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/annotate_dependency.html

Answering my own question again... Seems that, although you can embed Weblogic's JSF libraries into your own app (this is desirable for our company because we develop a product that should have little installation impact on several customers), the dependency injection and post-construct mechanisms only work if you actually deploy the library and refer to it.

This site helped me out: http://blog.eisele.net/2009/02/jsf-versions-and-weblogic-server.html

In a nutshell, I had to deploy Weblogic's JSF war as a library, remove its jars from my own app (also removed annotations-api), and add the following to my WEB-INF/weblogic.xml:

<library-ref>
  <library-name>jsf</library-name>
  <specification-version>1.2</specification-version>
  <implementation-version>1.2</implementation-version>
  <exact-match>false</exact-match>
</library-ref>

I also had to rewrite a couple beans which used @PostConstruct more than once. This works in Websphere, Jetty, and Tomcat, but Weblogic explicitly forbids using it more that once:

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/annotate_dependency.html

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