[英]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. 为了减少开发环境中的服务器启动时间,我想改变Spring的默认行为来懒惰地初始化bean。
I know this can be done by specifying default-lazy-init="true"
at the beans level. 我知道这可以通过在bean级别指定default-lazy-init="true"
来完成。 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. 但是我每次从SCM获取最新的配置文件时都不想更改此属性,并在重新检入之前将其更改回来。
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. 我还尝试在特定于环境的属性文件中定义属性并引用beans元素中的属性,但它不起作用。
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 如何在外部属性文件中使用default-lazy-init
并将其传递给bean定义
XML 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) 属性文件(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 ...如http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-lazy-init所述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.