Spring @Autowired @Lazy

ぃ、小莉子 提交于 2019-12-05 03:47:32

Because you're using @Autowired Long lazyParent, Spring will resolve that dependency when the context starts up. The fact that lazyBean is @Lazy is irrelevent.

Try this as an alternative, although I'm not 100% convinced this wil lwork as you want it to:

@Configuration
@Import(ConfigParent.class)
public class ConfigChild {

    private @Autowired ConfigParent configParent;

    @Bean
    public Double childBean() {
        System.out.println("loading child bean");
        return 1.0;
    }

    @Bean
    @Lazy
    public String lazyBean() {
        return configParent.lazyParent() + "!";
    }
}

P.S. I hope you're not really defining Strings, Doubles and Longs as beans, and that this is just an example. Right...?

Try

@Lazy @Autowired Long lazyParent;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!