2013-02-26 104 views
1

我想要初始化一個bean或一個ArrayList,就像應用程序中可以在應用程序範圍內跨會話使用的所有下拉列表中的鍵值對列表一樣。並希望在應用程序啓動過程中發生。我試着實現ServletContextListener並將bean添加到上下文中,但它不起作用。在Spring MVC中初始化應用程序範圍的bean

關於我如何實現這一點的任何建議。謝謝。

拉維

回答

0

定義規則(單身)的Spring bean和初始化值無論是在構造函數或方法@PostConstruct:

import javax.annotation.PostConstruct; 
@Component 
public class AppBean { 

@PostConstruct 
protected void init() { 
    // executed after dependencies have been injected. initialize values here 
} 

} 

http://www.mkyong.com/spring/spring-postconstruct-and-predestroy-example/的更詳細的例子

相關問題