這可能是由於我對Spring framewok的無知,但是我構建了一個JSF + Facelets + Spring web應用程序,我有一個bean,它的init方法我想在應用程序啓動的時間。我的問題是讓bean初始化。我可以在頁面上引用bean,當我進入頁面時,bean被初始化,並按照指示工作;我想反而是當應用程序啓動在web應用程序初始化的Spring bean啓動
是什麼讓一個Spring bean上的Web應用程序初始化的方法來初始化這個bean啓動
這可能是由於我對Spring framewok的無知,但是我構建了一個JSF + Facelets + Spring web應用程序,我有一個bean,它的init方法我想在應用程序啓動的時間。我的問題是讓bean初始化。我可以在頁面上引用bean,當我進入頁面時,bean被初始化,並按照指示工作;我想反而是當應用程序啓動在web應用程序初始化的Spring bean啓動
是什麼讓一個Spring bean上的Web應用程序初始化的方法來初始化這個bean啓動
你的問題是更Spring的針對性比JSF-有針對性的。我知道JSF的解決方案,但我不認爲這適合Spring bean。我搜索了一秒,在Spring論壇上發現了這個話題,可能對您有用。它描述/鏈接幾種不同的方法:http://forum.springsource.org/archive/index.php/t-21982.html
所有的代碼,你想一個web應用程序初始化可以在實現了ServletContextListener爲
@WebListener
public class ApplicationListener implements ServletContextListener {...}
一類完成後立即處理,你可以創建Spring應用程序上下文如
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
// of course, an ApplicationContext is just a BeanFactory
BeanFactory factory = context;
並獲得您感興趣的bean並繼續。