簡體   English   中英

Spring在開發環境中進行初始化

[英]Spring lazy initialization in development environment

為了減少開發環境中的服務器啟動時間,我想改變Spring的默認行為來懶惰地初始化bean。

我知道這可以通過在bean級別指定default-lazy-init="true"來完成。 但是我每次從SCM獲取最新的配置文件時都不想更改此屬性,並在重新檢入之前將其更改回來。

有沒有其他方法來外化這個屬性? 像指定一個系統屬性?

我還嘗試在特定於環境的屬性文件中定義屬性並引用beans元素中的屬性,但它不起作用。

default-lazy-init="${default-lazy-init-value}"

這可以輕松實現嗎?

如何在外部屬性文件中使用default-lazy-init並將其傳遞給bean定義

XML

<bean id="propertyPlaceholderConfigurer"  
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  <property name="locations">  
    <list>  
      <value>classpath:system-env.properties</value>  
    </list>  
  </property>  
</bean>  

<bean id="bean1" class="com.Foo" lazy="${default-lazy-init}"/>  

屬性文件(system-env.properties)

#set true in dev (if needed)
default-lazy-init=true

您可以使用以下內容:

<beans default-lazy-init="true">
<!-- no beans will be pre-instantiated... -->
</beans>

...如http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-lazy-init所述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM