2013-05-30 40 views
1

我正在使用spring 3.1。我需要在我的web根目錄在春天startUp做一個HTML文件。需要在啓動時創建web根文件夾中的html文件

當然,我知道JSP做了一個html,但它是關於請求響應。我需要在啓動時創建一個html。

And ..我希望我的工作在純粹的Spring框架中是可能的。

我知道石英..但我不想用石英。因爲恐怕採用Quartz可能需要在我的Spring配置中進行很多更改。

回答

1

您可以創建一個實現ApplicationListener的bean。 ApplicationListener監聽由上下文發佈的事件。

當加載 beans時,ApplicationContext發佈某些類型的事件。例如,當 上下文啓動時發佈ContextStartedEvent,並且當 上下文停止時發佈ContextStoppedEvent。

使用應用程序偵聽器可以在應用程序第一次啓動或上下文刷新時執行一些任務。

這裏是我的一個項目的基本ApplicationListener一個例子:

public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> { 

     @Override 
     public void onApplicationEvent(ContextRefreshedEvent event) { 
      //Generate html file here, this method is called when event happens 
     } 
    } 

而且它的配置:

<!-- Fired when different application events occur such as context refresh or startup --> 
<bean id="myListener" class="fully.qualified.MyApplicationListener" /> 
相關問題