gpt4 book ai didi

spring - Tomcat Spring WebApplicationContext

转载 作者:行者123 更新时间:2023-11-28 22:23:31 25 4
gpt4 key购买 nike

在 Spring 框架引用中我发现了这个:

The ApplicationContext interface has a few other methods for retrieving beans, but ideally your application code should never use them. Indeed, your application code should have no calls to the getBean method at all, and thus no dependency on Spring APIs at all.

但我不知道要实现这一点。

经过大量搜索,我找到了这个

avoid to use getBean in your application code, try to write a single class with one or more getBean() calls, this bootstrap class must be executed at the startup of your webapplication

这是更推荐的方式吗?

最佳答案

Spring 鼓励您使用 Inversion of Control ,其中框架(例如 Spring)将依赖项注入(inject)您的对象,而不是您的对象从框架中获取内容。

关于spring - Tomcat Spring WebApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3161127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com