2011-03-12 77 views
3

我不知道我做錯了,請幫忙:的Tomcat 7,JSF 2.0和@PostConstruct

  1. 新鮮的Tomcat 7的/ lib文件夾
  2. 簡單的網絡應用程序,沒有額外的罐子鑽嘴魚科2.0.3庫在WEB-INF/lib目錄(JSF-api.jar中,JSF-impl.jar中)
  3. 做工精細,除了@PostConstruct在我的豆子 - 他們不是在所有

日誌稱爲:

Mar 12, 2011 11:19:54 PM org.apache.catalina.startup.HostConfig deployWAR 
INFO: Deploying web application archive test_web_app.war 
Mar 12, 2011 11:19:54 PM com.sun.faces.config.ConfigureListener contextInitialized 
INFO: Initializing Mojarra 2.0.3 (FCS b03) for context '/test_web_app' 
Mar 12, 2011 11:19:54 PM com.sun.faces.spi.InjectionProviderFactory createInstance 
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed. 

的web.xml

<web-app 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-app_3_0.xsd" 
      version="3.0"> 

    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/faces/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

faces-config.xml中

<faces-config 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-facesconfig_2_0.xsd" 
       version="2.0"> 
</faces-config> 

豆與可達方法:

@ManagedBean 
@ApplicationScoped 
public class AppBean { 

    @PostConstruct 
    public void test() { 
    throw new RuntimeException("test"); 
    } 
} 

這就是全部。有任何想法嗎?

+0

整個堆棧跟蹤將有所幫助。隨着一些Google的快速搜索,我懷疑這不是問題。 –

+0

@Brian Roach,實際上整個堆棧是'2011年3月12日11:19:54 com.sun.faces.config.ConfigureListener contextInitialized 信息:初始化上下文的Mojarra 2.0.3(FCS b03)'/ test_web_app' '之前,我提到 – Osw

回答

5

如果您的應用程序範圍內管理的bean未在任何頁面中,你才能得到它在啓動時初始化

@ManagedBean(eager=true) 

進行註解。

+0

哇,我已經錯過了這樣一個簡單的事情,謝謝你的幫助。 – Osw

0

@PostConstruct應該工作,如果豆被加載,你可以直接調用或使用eager = true加載它,或者在構造函數中執行init。