Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 473
PrasadB Avatar asked Nov 28 '11 10:11

PrasadB


1 Answers

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
like image 80
jmj Avatar answered Nov 03 '22 17:11

jmj