6

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?

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

This will work. However this would require me to put the lazy attribute for all my beans. I hoped there was an easier way.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.