Weblogic 10.3.4 上的 @PostConstruct 注释未被调用
(这似乎是 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 ,症状相同。
如果需要的话我可以发布其他文件。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不使用 Weblogic,但如果我没记错的话,Weblogic 已经附带了它自己的 JSTL/JSF 库。所以您根本不需要自己提供它们。
但如果我错了并且 Weblogic 没有附带它们,那么这些库看起来就不太正确。到底是什么版本?
@PostConstruct
仅适用于 JSF 1.2 或更高版本。您可以在此处下载 JSF 1.2。它存在两个 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?
The
@PostConstruct
works on JSF 1.2 or newer only. You can download JSF 1.2 here. It exist of two JAR filesYou only need to ensure that your
faces-config.xml
is declared conform JSF 1.2 specification and also thatweb.xml
is declared conform at least Servlet 2.5 specification.Finally, the JSTL library should be this one.
再次回答我自己的问题...似乎,虽然您可以将 Weblogic 的 JSF 库嵌入到您自己的应用程序中(这对我们公司来说是可取的,因为我们开发的产品应该对多个客户的安装影响很小),但依赖项注入和发布-构造机制仅在您实际部署库并引用它时才起作用。
这个网站帮助了我:http://blog.eisele .net/2009/02/jsf-versions-and-weblogic-server.html
简而言之,我必须将 Weblogic 的 JSF war 部署为库,从我自己的应用程序中删除它的 jar(也删除
annotations-api
),并将以下内容添加到我的WEB-INF/weblogic.xml
中:我还必须重写一些使用
@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 myWEB-INF/weblogic.xml
: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