简体   繁体   中英

Spring lazy initialization in development environment

In order to reduce the server startup time in development envrionment, I would like to change the default behaviour of Spring to lazily initialize the beans.

I know this can be done by specifying default-lazy-init="true" at the beans level. However I would not want to change this property everytime I get the latest config files from SCM and change it back before checking it back in.

Is there any other way out to externalize this property? Like specifying a System property?

I also tried to define a property in an environment specific property file and refer to the property in beans element, but it did not work.

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

Any other way this can be achieved easily?

How about taking default-lazy-init in an external properties file and passing it to the bean definition

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}"/>  

Properties File (system-env.properties)

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

You could use the following:

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

...as described on http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-lazy-init

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM