Spring lazy initialization in development environment

To reduce server startup time in the development area, I would like to change Spring's default behavior for lazy beans initialization.

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

Is there any other way to externalize this property? How is specifying a System property?

I also tried to define the property in the environment properties file and refer to the property in the beans element, but this did not work.

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

Can it be easily achieved in any way?

+6
source share
2 answers

How to get default-lazy-init in an external properties file and pass it to a 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 
+3
source

You can use the following:

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

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

+1
source

Source: https://habr.com/ru/post/902533/


All Articles