中易网

Spring 的default-lazy-init="false" 如果没有xml使用@Configuration类,该怎么配置。

答案:1  悬赏:60  
解决时间 2021-02-21 14:10
Spring 的default-lazy-init="false" 如果没有xml使用@Configuration类,该怎么配置。
最佳答案
在@Configuration类上使用注解@Lazy.
下面是@Lazy的 JavaDoc:
Indicates whether a bean is to be lazily initialized.
May be used on any class directly or indirectly annotated with @Component or on methods annotated with @Bean.
If this annotation is not present on a @Component or @Bean definition, eager initialization will occur. If present and set to true, the @Bean or @Component will not be initialized until referenced by another bean or explicitly retrieved from the enclosing BeanFactory. If present and set to false, the bean will be instantiated on startup by bean factories that perform eager initialization of singletons.
If Lazy is present on a @Configuration class, this indicates that all @Bean methods within that @Configuration should be lazily initialized. If @Lazy is present and false on a @Bean method within a @Lazy-annotated @Configuration class, this indicates overriding the 'default lazy' behavior and that the bean should be eagerly initialized
大义是:@Lazy是用来控制懒加载的,可以直接或间接地用在@Compent 和@Bean 上;如果设置为 true, 则被调用时才会被加载,设置为 false, 则启动时加载;@Configuration 的@Lazy为默认@Lazy, 但是@Bean 上的@Lazy 可以覆盖@Configuration 的@Lazy
欢迎追问和评论
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
鑫林大酒店在什么地方啊,我要过去处理事情
如何把视频里的声音换成自己想要的音乐?
狼图腾大家看了么?说说各自的感受。我看完了
张古场在什么地方啊,我要过去处理事情
我需要一首向爱人表白的藏头诗,她叫苏丽娜,
詹姆斯11代战靴怎么样?轻吗,穿着舒服吗,求
男女关系很熟她对你的该是没有称呼还是有独一
面掌柜阜阳店怎么去啊,有知道地址的么
腹的形近字是什么?
遮放镇地址在哪,我要去那里办事
给狗刮毛的琉子价格
我CAD软件中下面的输命令的命令行不见了,在
御景嘉园在哪里啊,我有事要去这个地方
“未有揭阳先有槎桥”是为什么?
微店产品上传后,为什么不能修改
推荐资讯
《公文格式》中说的“2号小标宋体字”和“3号
亿香御宾馆停车场在哪里啊,我有事要去这个地
我现在每天都在后悔一件事总是在想如果当时那
皇爵休闲餐厅在什么地方啊,我要过去处理事情
smart gwt是什么
进军地产在哪里啊,我有事要去这个地方
吸血鬼日记里的特萨扮演者
无法提供法院要求的武功证明,怎么办
我是怎么从一个清洁工做到包装组长的文章
T型扳手都是有哪些规格
泰安市交警支队车管所泰安昌达机动车登记服务
急求数学问题
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?