Reputation: 381
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?
Upvotes: 6
Views: 4657
Reputation: 4491
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
Upvotes: 1
Reputation: 240900
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
Upvotes: 3