可以有2种方式实现bean的懒加载,一是让整个容器中的bean进行全局懒加载,二是通过配置让某个bean懒加载
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="true"
>
<bean id="lazyBean" class="cn.edu.tju.domain.LazyBeanClass" />
</beans>
或者。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="lazyBean" class="cn.edu.tju.domain.LazyBeanClass" lazy-init="true"/>
</beans>